Math object in Ruby

C

Charles Agriesti

In IRB, or saved as a program from Scite, put in something like:

puts(MATH::pI)

response is always " Uninitialized constant MATH(NameError)

How can I tell if I have the MATH module in my installation? If I don't
have it, how do I fix that? Thanks in advance.
 
S

Sam Duncan

Capitalisation issue?
ruby-1.9.2-p0 > puts Math::pI
3.141592653589793
=> nil
ruby-1.9.2-p0 > puts MATH::pI
NameError: uninitialized constant Object::MATH
from (irb):2
from /usr/home/sduncan/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `<main>'
ruby-1.9.2-p0 > defined?(Math)
=> "constant"
ruby-1.9.2-p0 > defined?(MATH)
=> nil


Sam
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

In IRB, or saved as a program from Scite, put in something like:

puts(MATH::pI)

response is always " Uninitialized constant MATH(NameError)

How can I tell if I have the MATH module in my installation? If I don't
have it, how do I fix that? Thanks in advance.
You could do something like this.

Object.constants.grep(/math/i) # => [:Math]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top