I’ve posted this before and never got an answer.
I’m learning to write Ruby using classes (as opposed to scripts).
I can’t get the following (extremely simple) class to run (although I
get the corresponding script right). What do I need to do to fix it?
Here is the class:
class Input1
def initialize(n1, n2)
@n1 = n1
@n2 = n2
end
def sum
@n1 + @n2
end
end
puts "Enter first number: "
@n1 = gets
puts "Enter second number: "
@n2 = gets
puts result = Input1(new).sum.to_s