Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8746: bigdecimal2.diff

File bigdecimal2.diff, 2.1 kB (added by vesaria, 1 year ago)

Fixes spelling error in patch comment

  • activesupport/test/bigdecimal_test.rb

    old new  
     1require File.dirname(__FILE__) + '/abstract_unit' 
     2require 'active_support/bigdecimal' 
     3 
     4class BigDecimalYamlTest < Test::Unit::TestCase 
     5  def test_to_yaml 
     6    assert_equal "--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml 
     7    assert_equal "--- .Inf\n", BigDecimal.new('Infinity').to_yaml 
     8    assert_equal "--- .NaN\n", BigDecimal.new('NaN').to_yaml 
     9  end 
     10end 
  • activesupport/lib/active_support/bigdecimal.rb

    old new  
     1require 'test/unit' 
     2require 'yaml' 
     3require 'bigdecimal' 
     4require 'rubygems' 
     5require 'active_support' 
     6 
     7class BigDecimal 
     8yaml_as "tag:yaml.org,2002:float" 
     9  def to_yaml( opts = {} ) 
     10    YAML::quick_emit( nil, opts ) do |out| 
     11      # This emits the number without any scientific notation. 
     12      # I prefer it to using self.to_f.to_s, which would lose precision. 
     13      # 
     14      # Note that YAML allows that when reconsituting floats 
     15      # to native types, some precision may get lost. 
     16      # There is no full precision real YAML tag that I am aware of. 
     17      str = self.to_s 
     18      if str == "Infinity" 
     19        str = ".Inf" 
     20      elsif str == "-Infinity" 
     21        str = "-.Inf" 
     22      elsif str == "NaN" 
     23        str = ".NaN" 
     24      end 
     25      out.scalar( "tag:yaml.org,2002:float", str, :plain ) 
     26    end 
     27  end 
     28end 
  • activesupport/lib/active_support.rb

    old new  
    4242require 'active_support/json' 
    4343 
    4444require 'active_support/multibyte' 
     45 
     46require 'active_support/bigdecimal'