common mistake I used to make always instationate a class and dont forget
your getter/setter method which in ruby is your _attr_aceessor it has the
getter setter both built in

On Sunday, August 3, 2014, Marc Chanliau <marc.chanliau / gmail.com> wrote:

> Thanks for the answer but that's not what I want to do. I want to use a
> keyboard dialog where I prompt the use to enter two values separately. I
> know how to write the script for that, I'm having problems with writing the
> equivalent 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
>
> Here is what happens when I run the class above:
>
> ~/desktop marcc$ ruby test1.rb
>
> Enter first number:
>
> 12
>
> Enter second number:
>
> 13
>
> test1.rb:19:in `<main>': undefined local variable or method `new' for
> main:Object (NameError)
>
>
>
> On Sun, Aug 3, 2014 at 6:16 PM, Brett Herford-Fell <brettskiii / gmail.com
> <javascript:_e(%7B%7D,'cvml','brettskiii / gmail.com');>> wrote:
>
>> result = Input1.new( 10, 20 ).sum.to_s
>>
>> = 30
>>
>> ?
>>
>>
>> On Mon, Aug 4, 2014 at 11:13 AM, Marc Chanliau <marc.chanliau / gmail.com
>> <javascript:_e(%7B%7D,'cvml','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
>>>
>>>
>>>
>>
>