C
Corey Konrad
I was wondering if i create a modules file called mathematics.rb:
module Mathematics
class Add
def add(operand_one, operand_two)
return operand_one + operand_two
end
end#end class
end
and then i create another file called usemodules.rb
require 'mathematics'
adder = Add.new
puts "2 + 3 = " + adder.add(2, 3).to_s
how do i create an Add object in this new file, i understand i could
just make the add method above into a class method and then i wouldnt
need to create an object at all. However how would i create an object to
use.
thanks
module Mathematics
class Add
def add(operand_one, operand_two)
return operand_one + operand_two
end
end#end class
end
and then i create another file called usemodules.rb
require 'mathematics'
adder = Add.new
puts "2 + 3 = " + adder.add(2, 3).to_s
how do i create an Add object in this new file, i understand i could
just make the add method above into a class method and then i wouldnt
need to create an object at all. However how would i create an object to
use.
thanks