Undefined method for main:Object

Hi,

I just installed ruby version 2.3.0.

I opened irb and entered sum(5,6) and I got this error:

NoMethodError: undefined method ‘sum’ for main:Object

Then I tried sqrt(25) and got the same error:

NoMethodError: undefined method ‘sqrt’ for main:Object

How can I fix this?

Thank you very much.

Hallo Rb Gem,

when something doesn’t work how you think it should you need to first
check the api, to see if the function your trying to call is
syntactically correct.

In both these cases, these functions don’t exist, at least, no as you’ve
called them. In general, ruby is an Object oriented language, you can
even send messages (call methods on) numbers:

5.times { |n| puts “Hello #{n}” }

You seem to be using functions in a C-language style. Anyway, to check
if the installation is correct, you can try using some of ruby’s core
classes:
http://ruby-doc.org/core-2.3.1/

Summing two numbers only requires using the + operator:
=> 1 + 2
=> 1 + 2 + 3 + 4

Or you can sum the elements in an array with reduce:

If you want the square root of a number, the documentation is here:

Happy rubying!

Hi Joe,

Thank you very much for your response. Will check API documentation.