Sha256: 2c539821940695bf30c7175623da6b6b8b15723d235f279a4d4bf32a5ae4a3cb

Contents?: true

Size: 892 Bytes

Versions: 119

Compression:

Stored size: 892 Bytes

Contents

require 'yaml'
require 'bigdecimal'
require 'rubygems'
require 'active_support'

class BigDecimal
  yaml_as "tag:yaml.org,2002:float"
  def to_yaml( opts = {} )
    YAML::quick_emit( nil, opts ) do |out|
            # This emits the number without any scientific notation. 
            # I prefer it to using self.to_f.to_s, which would loose precision.
            #
            # Note that YAML allows that when reconsituting floats 
            # to native types, some precision may get lost. 
            # There is no full precision real YAML tag that I am aware of.
            str = self.to_s
            if str == "Infinity"
                str = ".Inf"
            elsif str == "-Infinity"
                str = "-.Inf"
            elsif str == "NaN"
                str = ".NaN"
            end
            out.scalar( "tag:yaml.org,2002:float", str, :plain )
        end
  end
end

Version data entries

119 entries across 119 versions & 1 rubygems

Version Path
backlog-0.12.3 lib/big_decimal_yaml_fix.rb
backlog-0.12.4 lib/big_decimal_yaml_fix.rb
backlog-0.13.0 lib/big_decimal_yaml_fix.rb
backlog-0.14.0 lib/big_decimal_yaml_fix.rb
backlog-0.13.1 lib/big_decimal_yaml_fix.rb
backlog-0.14.2 lib/big_decimal_yaml_fix.rb
backlog-0.14.1 lib/big_decimal_yaml_fix.rb
backlog-0.14.3 lib/big_decimal_yaml_fix.rb
backlog-0.15.0 lib/big_decimal_yaml_fix.rb
backlog-0.14.4 lib/big_decimal_yaml_fix.rb
backlog-0.16.0 lib/big_decimal_yaml_fix.rb
backlog-0.15.1 lib/big_decimal_yaml_fix.rb
backlog-0.17.0 lib/big_decimal_yaml_fix.rb
backlog-0.17.2 lib/big_decimal_yaml_fix.rb
backlog-0.17.1 lib/big_decimal_yaml_fix.rb
backlog-0.17.3 lib/big_decimal_yaml_fix.rb
backlog-0.17.4 lib/big_decimal_yaml_fix.rb
backlog-0.17.5 lib/big_decimal_yaml_fix.rb
backlog-0.18.0 lib/big_decimal_yaml_fix.rb
backlog-0.17.6 lib/big_decimal_yaml_fix.rb