Forum: Ruby Methods from C Pine book -- need some help understanding the basic concepts

F7a303c5a1c75abbddf699280aca8408?d=identicon&s=25 James Smith (newby)
on 2014-04-02 23:56
Newbie question. I'm using C Pine's great book on Intro to Programming
with Ruby and am stuck on the code in ch8 and I do not get it at all...
the code and my comments or where I get stuck are here:
http://codepad.org/rjhEy2eg
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-04-06 17:18
In Ruby, any standard mathematics involving two Integers will result an
an Integer unless you specifically alter one of the operands to a Float
(or something else).

It works because according to those rules:

3 / 10 = 0

3.0 / 10 = 0.3

3.to_f / 10 = 0.3

So in the operations performed, he's relying on the way Integers (Fixnum
Class) behave.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.