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)
Steve_Ross
(Steve Ross)
December 31, 2007, 7:04pm
2
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 (Class: Module (Ruby 3.1.2) ).
attr_writer :picture_attributes
automagically defines a getter that takes one value argument (Class: Module (Ruby 3.1.2) ).
attr_accessor :picture_attributes
automagically defines both (Class: Module (Ruby 3.1.2) ).