Created
January 13, 2011 14:23
-
-
Save colszowka/777923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Works as expected | |
$ rvm use 1.9.2 | |
Using /Users/colszowka/.rvm/gems/ruby-1.9.2-p136 | |
~ 1.9.2-p136 $ irb | |
>> "1.9".respond_to?(:encoding) | |
=> true | |
>> 7.123.round | |
=> 7 | |
>> 7.123.round(2) | |
=> 7.12 | |
>> exit | |
# Fails just as expected | |
$ rvm use 1.8.7 | |
Using /Users/colszowka/.rvm/gems/ruby-1.8.7-p330 | |
~ 1.8.7-p330 $ irb | |
>> "1.9".respond_to?(:encoding) | |
=> false | |
>> 7.123.round | |
=> 7 | |
>> 7.123.round(2) | |
ArgumentError: wrong number of arguments (1 for 0) | |
from (irb):3:in `round' | |
from (irb):3 | |
>> exit | |
# Sholdn't fail in 1.9 mode | |
$ rvm use jruby-1.6.0.RC1 | |
Using /Users/colszowka/.rvm/gems/jruby-1.6.0.RC1 | |
~ j1.6.0.RC1 $ ruby --1.9 -S irb | |
>> "1.9".respond_to?(:encoding) | |
=> true | |
>> 7.123.round | |
=> 7 | |
>> 7.123.round(2) | |
ArgumentError: wrong number of arguments (1 for 0) | |
from (irb):3:in `evaluate' | |
from org/jruby/RubyKernel.java:1096:in `eval19' | |
from org/jruby/RubyKernel.java:1421:in `loop' | |
from org/jruby/RubyKernel.java:1208:in `rbCatch19' | |
from org/jruby/RubyKernel.java:1208:in `rbCatch19' | |
>> exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem can be temporarily fixed with this code from ActiveSupport's rounding:
class Float
alias_method :precisionless_round, :round
def round(precision = nil)
if precision
magnitude = 10.0 ** precision
(self * magnitude).round / magnitude
else
precisionless_round
end
end
end