aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type
diff options
context:
space:
mode:
authorMariano Valles <mariano.valles@wooga.com>2014-07-16 16:08:35 +0200
committerMariano Valles <mariano.valles@wooga.com>2014-07-16 16:08:35 +0200
commit7098c9083ccd08eb36cce5abcc99ad0506945ef0 (patch)
tree1b05f8f95a5a237037519e6244da59263b3606e4 /activerecord/lib/active_record/type
parenta4802e217e95af14ca6ae13ab72ff3b44e2b4217 (diff)
downloadrails-7098c9083ccd08eb36cce5abcc99ad0506945ef0.tar.gz
rails-7098c9083ccd08eb36cce5abcc99ad0506945ef0.tar.bz2
rails-7098c9083ccd08eb36cce5abcc99ad0506945ef0.zip
Change class evaluation for Rationals in cast_value
Diffstat (limited to 'activerecord/lib/active_record/type')
-rw-r--r--activerecord/lib/active_record/type/decimal.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/type/decimal.rb b/activerecord/lib/active_record/type/decimal.rb
index 33d4e37ea3..1c7edc12f5 100644
--- a/activerecord/lib/active_record/type/decimal.rb
+++ b/activerecord/lib/active_record/type/decimal.rb
@@ -14,14 +14,16 @@ module ActiveRecord
private
def cast_value(value)
- if value.class == Rational
- BigDecimal.new(value, precision.to_i)
- elsif value.respond_to?(:to_d)
+ case value
+ when Numeric, String, Rational
+ BigDecimal(value, precision.to_i)
+ when proc { value.respond_to?(:to_d) }
value.to_d
else
- value.to_s.to_d
+ cast_value(value.to_s)
end
end
+
end
end
end