Here ya go...
require "cases/helper"
require 'models/post'
require 'models/author'
class Object
def full?
is_full = !blank?
if is_full and block_given?
instance_eval(&Proc.new)
else
is_full
end
end
end
class ProxySendTest < ActiveRecord::TestCase
fixtures :authors, :posts
def test_send
self_is_author = nil
post = Post.first
post.author.full?{ self_is_author = self == post.author }
assert self_is_author
end
end
That test will pass with the old implementation of
AssociationProxy#method_missing, but not the new.
I do realize that that implementation of full? can lead to confusion
and there is a good argument for it not to behave that way, but dang
it, it makes for some pretty code sometimes...
# dry
a.very.long.assocation.chain.full?{ name } || "(no name)"
page = params[:page].full?{ to_i } || 1
vs.
# wet
a.very.long.assocation.chain.full? ?
a.very.long.assocation.chain.name : "(no name)"
page = params[:page].full? ? params[:page].to_i : 1
-- C
P.S. I think yall should put this implementation of #full? in Rails,
as well as change #blank? to optionally take a block. :)
On Sep 3, 2:45 am, "Michael Koziarski" <[EMAIL PROTECTED]> wrote:
> > I'm just curious why the change... and wondering if there is a way to
> > make it compatible with my full? implementation so I won't have to go
> > refactor tons of code.
>
> The change was made to reduce the memory consumption and garbage
> generated when you have an explicit block parameter. However if it's
> breaking things we can look at reverting it. It was *meant* to be
> fully backwards compatible.
>
> If you can add a test for what you're doing, it'd make it easier for
> us to figure out the best way forward.
>
> --
> Cheers
>
> Koz
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---