Square root?

J

Jeffrey

rayreeves said:
Much obliged for your attention. As you can tell I am new to Ruby.
Your tip works ok but I am not sure what I am doing, I thought I
would have to 'require alibrary'. What I need now is 'floor' and
that doesn't seem to be a Math method.

Some modules, like Math, are loaded automatically, so you don't have
to use 'require' explicitly. Numeric types happen to have their own
floor methods:

irb(main):001:0> s2 = Math.sqrt(2)
=> 1.4142135623731
irb(main):002:0> s2.floor
=> 1
irb(main):003:0>

In general, the best tool to use when looking for a particular method
is ri. The ri command searches for documentation relevant to whatever
type or method you specify. Here's an example:

shell>ri -T floor
More than one method matched your request. You can refine
your search by asking for information on one of:

Float#floor, Integer#floor, Numeric#floor

The Class#method notation means that the method should be called on
instances of the class, rather than on the class itself. The
documentation here says that any Float, Integer, or Numeric object
will have a floor method.
 

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
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top