From f57bafe44b14f836a8c28f9a5f187d4876499621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 17 Jul 2014 17:47:03 -0300 Subject: 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 --- activerecord/lib/active_record/type/decimal.rb | 5 ++--- 1 file 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) -- cgit v1.2.3