On Mon, 2011-08-29 at 04:18 -0700, Daniel Schierbeck wrote:
> @jonleighton thanks for chiming in. I really believe that the basic
> constructs provided by ActiveSupport should uphold the rules of OOP -
> if you need to delegate to a private method nothing is stopping you
> from going the manual route.
> 
> I seem to have fixed the performance issues, although I completely
> removed the ability to delegate to private methods, rather than
> deprecating it like you did.
> 
> I've created a pull request so that the changes are more apparent:
> https://github.com/rails/rails/pull/2733

I removed the ability in master, and deprecated it in 3-1-stable. If we
make this change, we do need to give people an upgrade path, so there
does need to be a deprecation before the change is actually made.

One feature of your implementation is that the following will not work:

class Foo
  delegate :foo=, :to => :bar
end

foo.send(:foo=, 1, 2)
# => will do 'foo.bar.foo = 1', not 'foo.bar.send(:foo=, 1, 2)'

I think this is reasonable because this is a quite esoteric usage of a
writer method. However, we should raise ArgumentError if there are
multiple arguments in this case, and again we would need to provide a
deprecation.

I think checking args.length for writer methods should be performant
enough for the deprecation. Then, in the future implementation, we could
just define writer methods with no splat, so Ruby would take care of
raising the ArgumentError.

Jon

-- 
http://jonathanleighton.com/

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to