Daniel Schierbeck
2008-Oct-11 19:06 UTC
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? <http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/ 984> --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick
2008-Oct-12 17:31 UTC
Re: Request for Review: Make it possible to prefix delegate methods
Why wouldn''t you just do obj.client.name and obj.client.address if you''re looking to keep some context in the names? On Sat, Oct 11, 2008 at 2:06 PM, Daniel Schierbeck <daniel.schierbeck@gmail.com> wrote:> > 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? > > > <http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/ > 984> > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick
2008-Oct-12 17:33 UTC
Re: Request for Review: Make it possible to prefix delegate methods
Also if you''re looking for some alternate method names, wouldn''t the use of "alias" help? On Sun, Oct 12, 2008 at 12:31 PM, Andrew Kaspick <akaspick@gmail.com> wrote:> Why wouldn''t you just do obj.client.name and obj.client.address if > you''re looking to keep some context in the names? > > On Sat, Oct 11, 2008 at 2:06 PM, Daniel Schierbeck > <daniel.schierbeck@gmail.com> wrote: >> >> 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? >> >> >> <http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/ >> 984> >> >> >> >> >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Schierbeck
2008-Oct-12 20:26 UTC
Re: Request for Review: Make it possible to prefix delegate methods
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> 2. <http://blog.jayfields.com/2006/05/law-of-demeter-and- forwardable.html> Best regards Daniel Schierbeck On Oct 12, 7:31 pm, "Andrew Kaspick" <akasp...@gmail.com> wrote:> Why wouldn''t you just do obj.client.name and obj.client.address if > you''re looking to keep some context in the names? > > On Sat, Oct 11, 2008 at 2:06 PM, Daniel Schierbeck > > <daniel.schierb...@gmail.com> wrote: > > > 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? > > > <http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/ > > 984> > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Martin Gamsjaeger
2008-Oct-13 12:09 UTC
Re: Request for Review: Make it possible to prefix delegate methods
Just want to say that I would really like that too! On Sun, Oct 12, 2008 at 10:26 PM, Daniel Schierbeck < daniel.schierbeck@gmail.com> wrote:> > 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> > 2. <http://blog.jayfields.com/2006/05/law-of-demeter-and- > forwardable.html<http://blog.jayfields.com/2006/05/law-of-demeter-and-forwardable.html> > > > > > Best regards > Daniel Schierbeck > > On Oct 12, 7:31 pm, "Andrew Kaspick" <akasp...@gmail.com> wrote: > > Why wouldn''t you just do obj.client.name and obj.client.address if > > you''re looking to keep some context in the names? > > > > On Sat, Oct 11, 2008 at 2:06 PM, Daniel Schierbeck > > > > <daniel.schierb...@gmail.com> wrote: > > > > > 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? > > > > > <http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/ > > > 984> > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---