aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-07-17 17:47:03 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-07-17 17:47:03 -0300
commitf57bafe44b14f836a8c28f9a5f187d4876499621 (patch)
tree4f665ca18a3cb7003789a3cbb56a1ee23915b332 /activerecord
parent8e3d9438390c6277ee14f00f773d2c440e7cf4d5 (diff)
downloadrails-f57bafe44b14f836a8c28f9a5f187d4876499621.tar.gz
rails-f57bafe44b14f836a8c28f9a5f187d4876499621.tar.bz2
rails-f57bafe44b14f836a8c28f9a5f187d4876499621.zip
Prefer if/else for this case
One of the branches is using a proc to check if the value respond_to a method so it is better to not do case comparations
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/type/decimal.rb5
1 files changed, 2 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/type/decimal.rb b/activerecord/lib/active_record/type/decimal.rb
index 27566cf856..ba5d244729 100644
--- a/activerecord/lib/active_record/type/decimal.rb
+++ b/activerecord/lib/active_record/type/decimal.rb
@@ -14,10 +14,9 @@ module ActiveRecord
private
def cast_value(value)
- case value
- when ::Numeric, ::String
+ if value.is_a?(::Numeric) || value.is_a?(::String)
BigDecimal(value, precision.to_i)
- when proc { value.respond_to?(:to_d) }
+ elsif value.respond_to?(:to_d)
value.to_d
else
cast_value(value.to_s)