diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-17 17:47:03 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-17 17:47:03 -0300 |
commit | f57bafe44b14f836a8c28f9a5f187d4876499621 (patch) | |
tree | 4f665ca18a3cb7003789a3cbb56a1ee23915b332 /activerecord/lib | |
parent | 8e3d9438390c6277ee14f00f773d2c440e7cf4d5 (diff) | |
download | rails-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/lib')
-rw-r--r-- | activerecord/lib/active_record/type/decimal.rb | 5 |
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) |