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

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -