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.37.2 lib/big_decimal_yaml_fix.rb
backlog-0.37.1 lib/big_decimal_yaml_fix.rb
backlog-0.36.2 lib/big_decimal_yaml_fix.rb
backlog-0.0.5 lib/big_decimal_yaml_fix.rb
backlog-0.1.0 lib/big_decimal_yaml_fix.rb
backlog-0.1.1 lib/big_decimal_yaml_fix.rb
backlog-0.1.2 lib/big_decimal_yaml_fix.rb
backlog-0.10.0 lib/big_decimal_yaml_fix.rb
backlog-0.10.1 lib/big_decimal_yaml_fix.rb
backlog-0.10.4 lib/big_decimal_yaml_fix.rb
backlog-0.10.2 lib/big_decimal_yaml_fix.rb
backlog-0.10.3 lib/big_decimal_yaml_fix.rb
backlog-0.10.5 lib/big_decimal_yaml_fix.rb
backlog-0.10.7 lib/big_decimal_yaml_fix.rb
backlog-0.10.6 lib/big_decimal_yaml_fix.rb
backlog-0.12.0 lib/big_decimal_yaml_fix.rb
backlog-0.11.0 lib/big_decimal_yaml_fix.rb
backlog-0.10.8 lib/big_decimal_yaml_fix.rb
backlog-0.12.2 lib/big_decimal_yaml_fix.rb
backlog-0.12.1 lib/big_decimal_yaml_fix.rb