Print out the instance variable : instance variables « Class « Ruby






Print out the instance variable


class Hello
  def initialize( name )
    @name = name
  end

  def hello_matz
    puts "Hello, " + @name + "!"
  end

end

hi = Hello.new( "Matz" )
hi.hello_matz # => Hello, Matz!

 








Related examples in the same category

1.In Ruby, you prefix instance variables with an at sign @
2.Using a Constructor to Configure Objects
3.Adding more accessors
4.class variable vs object variable