Ruby - Class Instance Variables


Variables beginning with the at sign @ are instance variables.

They belong to individual instances of the class.

You can create instances of the Dog class by calling the new method.

class Dog 
   def set_name( aName ) 
      @myname = aName 

mydog = 
yourdog = 

At the moment, these two dogs have no names.

Call the set_name method to give them names:

mydog.set_name( 'Fido' ) 
yourdog.set_name( 'Bonzo' ) 

Related Topic