Request for Review: Make it possible to prefix delegate methods

I've submitted a patch to Lighthouse which makes it possible to prefix delegation methods, i.e.:

  delegate :name, :address, :to => :client, :prefix => true

Which would create the methods #client_name and #client_address. It's also possible to give a custom prefix, e.g. :customer.

Could I get someone to take a look at this patch?

<Tickets - Ruby on Rails - rails 984>

Why wouldn't you just do obj.client.name and obj.client.address if you're looking to keep some context in the names?

Also if you're looking for some alternate method names, wouldn't the use of "alias" help?

The theoretic basis for the proposal stems from the Law of Demeter[1], which basically states that you should “only talk to your immediate friends.”, meaning that `obj.client.name' makes assumptions about the inner structure of `client', while `obj.client_name' doesn't. A more general Ruby discussion[2] shows how to delegate properly with the Forwardable mixin. Since Rails uses the ActiveSupport delegation, I've tried to implement some of the ideas there.

1. <http://en.wikipedia.org/wiki/Law_Of_Demeter&gt; 2. <http://blog.jayfields.com/2006/05/law-of-demeter-and- forwardable.html>

Best regards Daniel Schierbeck

Just want to say that I would really like that too!