Ruby - Class Instance Variables

Introduction

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 
   end 
end 

mydog = Dog.new 
yourdog = Dog.new 

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