$ cd /tmp
$ rails new t1
$ cd t1
$ rails console
Loading development environment (Rails 3.2.9)
irb(main):001:0> 2 / 5
=> 0
irb(main):002:0> 2.to_f / 5.to_f
=> 0.4
So I just don’t get why 2/5 doesn’t return the same result in both
cases.
Personally, I found this behaviour dangerous since many third party
libraries will be based on it. I had a quick look at Active Support Core Extensions — Ruby on Rails Guides but
could
not find any mention of it.
Can someone explain me why and how Rails does that?
That’s not how it behaves for me. I get 2 / 5 == 0 in both cases. The
ruby
mathn library (part of the stdlib) does do this (and I really wish it
wouldn’t). Perhaps something in your irbrc pulls this in ?
On Fri, Dec 7, 2012 at 12:46 PM, Frederick C. < [email protected]> wrote:
strange behaviour drift between Rails and Ruby:
That’s not how it behaves for me. I get 2 / 5 == 0 in both cases. The ruby
mathn library (part of the stdlib) does do this (and I really wish it
wouldn’t). Perhaps something in your irbrc pulls this in ?
Not .irbrc. I forgot I had an alias on irb which pull -m option…
So
the error was from my environment. Thanks for your reply.
Sorry for the noise.
–
Nicolas D.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.