Creating Class Methods : Class Methods « Class « Ruby






Creating Class Methods


# Besides class variables, you can create class methods in Ruby. 

# You can call a class method using just the name of the class. 

class Mathematics
  def Mathematics.add(operand_one, operand_two)
    return operand_one + operand_two
  end
end


puts "1 + 2 = " + Mathematics.add(1, 2).to_s

 








Related examples in the same category

1.The area method is made available in all objects of class Square,
2.Class methods give you the mechanism to properly implement the object counter
3.Static class method