mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove hack to support BigDecimal in Ruby 1.9
Now that Rails requires Ruby >= 2.0, there is no need to check whether `BigDecimal` exists or not.
This commit is contained in:
parent
b2bb2a462f
commit
7926ab1004
2 changed files with 3 additions and 21 deletions
|
@ -78,17 +78,8 @@ end
|
||||||
|
|
||||||
require 'bigdecimal'
|
require 'bigdecimal'
|
||||||
class BigDecimal
|
class BigDecimal
|
||||||
# Needed to support Ruby 1.9.x, as it doesn't allow dup on BigDecimal, instead
|
def duplicable?
|
||||||
# raises TypeError exception. Checking here on the runtime whether BigDecimal
|
true
|
||||||
# will allow dup or not.
|
|
||||||
begin
|
|
||||||
BigDecimal.new('4.56').dup
|
|
||||||
|
|
||||||
def duplicable?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
rescue TypeError
|
|
||||||
# can't dup, so use superclass implementation
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,7 @@ require 'active_support/core_ext/numeric/time'
|
||||||
class DuplicableTest < ActiveSupport::TestCase
|
class DuplicableTest < ActiveSupport::TestCase
|
||||||
RAISE_DUP = [nil, false, true, :symbol, 1, 2.3, method(:puts)]
|
RAISE_DUP = [nil, false, true, :symbol, 1, 2.3, method(:puts)]
|
||||||
ALLOW_DUP = ['1', Object.new, /foo/, [], {}, Time.now, Class.new, Module.new]
|
ALLOW_DUP = ['1', Object.new, /foo/, [], {}, Time.now, Class.new, Module.new]
|
||||||
|
ALLOW_DUP << BigDecimal.new('4.56')
|
||||||
# Needed to support Ruby 1.9.x, as it doesn't allow dup on BigDecimal, instead
|
|
||||||
# raises TypeError exception. Checking here on the runtime whether BigDecimal
|
|
||||||
# will allow dup or not.
|
|
||||||
begin
|
|
||||||
bd = BigDecimal.new('4.56')
|
|
||||||
ALLOW_DUP << bd.dup
|
|
||||||
rescue TypeError
|
|
||||||
RAISE_DUP << bd
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_duplicable
|
def test_duplicable
|
||||||
RAISE_DUP.each do |v|
|
RAISE_DUP.each do |v|
|
||||||
|
|
Loading…
Reference in a new issue