> On Dec 31, 2007, at 10:57 AM, Anthony Ettinger wrote:
> I saw in episode #75 that creating a method in the Product model will
> update attributes related to a different model (Picture):
>
> def picture_attributes=(picture_attributes)
> ...
> end
>
> I''m unclear as to the first line:
>
> def picture_attributes=(picture_attributes)
> vs.
> def picture_attributes (picture_attributes)
def picture_attributes
defines the setter, whereas
def picture_attributes
defines the getter
It is unusual for a getter to take a parameter because getters are not
supposed to have side-effects, just return a value. More rubyish names
for these functions are "accessors" so declaring:
attr_reader :picture_attributes
automagically defines a getter
(http://ruby-doc.org/core/classes/Module.html#M001702
).
attr_writer :picture_attributes
automagically defines a getter that takes one value argument
(http://ruby-doc.org/core/classes/Module.html#M001703
).
attr_accessor :picture_attributes
automagically defines both (http://ruby-doc.org/core/classes/Module.html#M001704
).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---