Ruby symbol and attribute -
when i'm creating attributes, can use symbols this:
class someclass attr_reader :variable1, :variable2 end
when i'm using keyword attr_reader
(or attr_writer
) , use same name instance variable, ruby automatically associate attribute (or say, property) instance variable same name?
you need understand attr_reader
does. when do:
attr_reader :variable1, :variable2
it gets translated into:
def variable1 @variable1 end def variable2 @variable2 end
as can see variable1
instance variable @variable1
value setting within initialize
method.
so yes, ruby associate attribute instance variable same name.
Comments
Post a Comment