The area method is made available in all objects of class Square, : Class Methods « Class « Ruby






The area method is made available in all objects of class Square,

# so it's considered to be an object method.

class Square
  def initialize(side_length)
    @side_length = side_length
  end

  def area
    @side_length * @side_length
  end
end

 








Related examples in the same category

1.Creating Class Methods
2.Class methods give you the mechanism to properly implement the object counter
3.Static class method