Define a method to retrieve the value. : Member method « Class « Ruby






Define a method to retrieve the value.


class Horse
  def name
    @name = "Easy Jet"
  end

end

h = Horse.new
h.name

# The method name is the kind of method that is referred to as an accessor method or getter. 
# It gets a property (the value of a variable) from an instance of a class.

 








Related examples in the same category

1.a simple demonstration of a class with two methods
2.implement an each method, and get these methods for "free":
3.Compare method
4.Add method to a variable only
5.Defining Methods within a Class