diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2018-12-21 10:28:06 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2018-12-21 10:28:06 +0900 |
commit | d5f8486d3f861f9848f4cd919fcdc33fe9f43dca (patch) | |
tree | 4d9127c93dc893c28cf15516b6a942603b6a4855 | |
parent | 1ff22133139b3c8aa4fb9b691b677aa0e697ea77 (diff) | |
download | rails-d5f8486d3f861f9848f4cd919fcdc33fe9f43dca.tar.gz rails-d5f8486d3f861f9848f4cd919fcdc33fe9f43dca.tar.bz2 rails-d5f8486d3f861f9848f4cd919fcdc33fe9f43dca.zip |
Use BigDecimal provided methods to convert String to BigDecimal
`String#to_d` does not raise an exception if an invalid value is specified.
So can remove exception handling.
```
$ bundle exec ruby -v -rbigdecimal -rbigdecimal/util -e 'p "123,003".to_d'
ruby 2.6.0dev (2018-12-21 trunk 66474) [x86_64-linux]
0.123e3
```
-rw-r--r-- | activesupport/lib/active_support/xml_mini.rb | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index be298bf0a1..b5995d6fe9 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -68,11 +68,7 @@ module ActiveSupport "float" => Proc.new { |float| float.to_f }, "decimal" => Proc.new do |number| if String === number - begin - BigDecimal(number) - rescue ArgumentError - BigDecimal(number.to_f.to_s) - end + number.to_d else BigDecimal(number) end |