diff options
author | Richard Schneeman <richard.schneeman@gmail.com> | 2016-04-12 13:40:17 -0700 |
---|---|---|
committer | Richard Schneeman <richard.schneeman@gmail.com> | 2016-04-12 13:40:17 -0700 |
commit | ecd53667fa814023d3434fca0629e19bad46b092 (patch) | |
tree | 5c19be65aba33c5c24cf87c308891d388d40d431 /activesupport | |
parent | b1f10502e6e75c2198efe22e527d688bcd3ad4a7 (diff) | |
parent | 9c30e1b167054aa57e56e1df5a9e151c70332522 (diff) | |
download | rails-ecd53667fa814023d3434fca0629e19bad46b092.tar.gz rails-ecd53667fa814023d3434fca0629e19bad46b092.tar.bz2 rails-ecd53667fa814023d3434fca0629e19bad46b092.zip |
Merge pull request #24502 from ankit8898/freezing-dot-in-delimiter-helper
Lesser '.' objects for number helpers
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb b/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb index 45ae8f1a93..43c5540b6f 100644 --- a/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb @@ -12,7 +12,7 @@ module ActiveSupport private def parts - left, right = number.to_s.split('.') + left, right = number.to_s.split('.'.freeze) left.gsub!(delimiter_pattern) do |digit_to_delimit| "#{digit_to_delimit}#{options[:delimiter]}" end diff --git a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb index 981c562551..9fb7dfb779 100644 --- a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb @@ -29,9 +29,11 @@ module ActiveSupport formatted_string = if BigDecimal === rounded_number && rounded_number.finite? - s = rounded_number.to_s('F') + '0'*precision - a, b = s.split('.', 2) - a + '.' + b[0, precision] + s = rounded_number.to_s('F') + s << '0'.freeze * precision + a, b = s.split('.'.freeze, 2) + a << '.'.freeze + a << b[0, precision] else "%00.#{precision}f" % rounded_number end |