I am doing the Ruby Monk tutorial and got stuck on a problem. Here it is:
“Write a method called add_two that adds 2 to any number passed to it and returns the result. Yes, please feel free to experiment using next in addition to the more obvious route of simply adding the integer 2 to the incoming number.”
I started with:
def add_two(number)
number + number
end
But i am not sure how to account for negative numbers
Any help would be great!
Basically what they are asking you to do is to use
nextwhich is a method of the Integer class.Ruby API – Integer#next
It should look something like this