Re: [Rails-core] Delegate default value option
I like this idea and would use it. -Amiel http://carnesmedia.com On Fri, Dec 13, 2013 at 2:44 PM, Scott Johnson 7.scot...@gmail.com wrote: I find I often use delegate and many nil guards in my facades. Adding a default_value option to delegate would simplify this, but I am interested how others feel about it. Implementation would look something like: class PersonFacade delegate :name, :to = :person, :default_value = def initialize(person) @person = person end end p = Person.find p.name = nil f = PersonFacade.new(p) f.name = -- Scott Johnson -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Rails-core] Delegate default value option
Thanks. I will work up a pull request and see if I can get it added. On Mon, Dec 16, 2013 at 11:37 AM, Amiel Martin am...@carnesmedia.comwrote: I like this idea and would use it. -Amiel http://carnesmedia.com On Fri, Dec 13, 2013 at 2:44 PM, Scott Johnson 7.scot...@gmail.comwrote: I find I often use delegate and many nil guards in my facades. Adding a default_value option to delegate would simplify this, but I am interested how others feel about it. Implementation would look something like: class PersonFacade delegate :name, :to = :person, :default_value = def initialize(person) @person = person end end p = Person.find p.name = nil f = PersonFacade.new(p) f.name = -- Scott Johnson -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out. -- Scott Johnson -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Rails-core] Delegate default value option
What is the advantage over? def name person.name || end I am really against adding new options to delegate method since all that it does is define methods like this in the class. Rafael Mendonça França http://twitter.com/rafaelfranca https://github.com/rafaelfranca On Mon, Dec 16, 2013 at 5:41 PM, Scott Johnson 7.scot...@gmail.com wrote: Thanks. I will work up a pull request and see if I can get it added. On Mon, Dec 16, 2013 at 11:37 AM, Amiel Martin am...@carnesmedia.comwrote: I like this idea and would use it. -Amiel http://carnesmedia.com On Fri, Dec 13, 2013 at 2:44 PM, Scott Johnson 7.scot...@gmail.comwrote: I find I often use delegate and many nil guards in my facades. Adding a default_value option to delegate would simplify this, but I am interested how others feel about it. Implementation would look something like: class PersonFacade delegate :name, :to = :person, :default_value = def initialize(person) @person = person end end p = Person.find p.name = nil f = PersonFacade.new(p) f.name = -- Scott Johnson -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out. -- Scott Johnson -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Rails-core] Delegate default value option
On Dec 13, 2013, at 5:44 PM, Scott Johnson wrote: I find I often use delegate and many nil guards in my facades. Adding a default_value option to delegate would simplify this, but I am interested how others feel about it. Implementation would look something like: class PersonFacade delegate :name, :to = :person, :default_value = It's not clear (to me) how this should interact with passing multiple attributes to `delegate`: delegate :foo, :bar, :baz, :to = :person Also, should the default value be returned if :allow_nil is set and the delegated-to object isn't present? --Matt Jones -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Rails-core] Delegate default value option
This is why I wanted to ask the group before making the pull request. As for Rafael's question -- it is no different from writing the methods out, but either is delegate. I just found that many times where I would have used delegate I ended up writing out the individual methods only to add || = . So, I thought others might use it as well. As for Matt's questions: (1) It's not clear (to me) how this should interact with passing multiple attributes to `delegate`: The way I wrote it all of the delegated methods passed would get the default values so: delegate :foo, :bar, :to = :person, :default_value = delegate :baz, :to = :person foo = bar = baz = nil (2) Also, should the default value be returned if :allow_nil is set and the delegated-to object isn't present? Yes. On Mon, Dec 16, 2013 at 2:01 PM, Matt Jones al2o...@gmail.com wrote: On Dec 13, 2013, at 5:44 PM, Scott Johnson wrote: I find I often use delegate and many nil guards in my facades. Adding a default_value option to delegate would simplify this, but I am interested how others feel about it. Implementation would look something like: class PersonFacade delegate :name, :to = :person, :default_value = It's not clear (to me) how this should interact with passing multiple attributes to `delegate`: delegate :foo, :bar, :baz, :to = :person Also, should the default value be returned if :allow_nil is set and the delegated-to object isn't present? --Matt Jones -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out. -- Scott Johnson -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Rails-core] Delegate default value option
We already rejected this feature before. See https://github.com/rails/rails/pull/11908 Rafael Mendonça França http://twitter.com/rafaelfranca https://github.com/rafaelfranca On Mon, Dec 16, 2013 at 6:20 PM, Scott Johnson 7.scot...@gmail.com wrote: This is why I wanted to ask the group before making the pull request. As for Rafael's question -- it is no different from writing the methods out, but either is delegate. I just found that many times where I would have used delegate I ended up writing out the individual methods only to add || = . So, I thought others might use it as well. As for Matt's questions: (1) It's not clear (to me) how this should interact with passing multiple attributes to `delegate`: The way I wrote it all of the delegated methods passed would get the default values so: delegate :foo, :bar, :to = :person, :default_value = delegate :baz, :to = :person foo = bar = baz = nil (2) Also, should the default value be returned if :allow_nil is set and the delegated-to object isn't present? Yes. On Mon, Dec 16, 2013 at 2:01 PM, Matt Jones al2o...@gmail.com wrote: On Dec 13, 2013, at 5:44 PM, Scott Johnson wrote: I find I often use delegate and many nil guards in my facades. Adding a default_value option to delegate would simplify this, but I am interested how others feel about it. Implementation would look something like: class PersonFacade delegate :name, :to = :person, :default_value = It's not clear (to me) how this should interact with passing multiple attributes to `delegate`: delegate :foo, :bar, :baz, :to = :person Also, should the default value be returned if :allow_nil is set and the delegated-to object isn't present? --Matt Jones -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out. -- Scott Johnson -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.