result = Input1.new( 10, 20 ).sum.to_s

= 30

?


On Mon, Aug 4, 2014 at 11:13 AM, Marc Chanliau <marc.chanliau / gmail.com>
wrote:

> 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
>
>
>