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.2.0 lib/big_decimal_yaml_fix.rb
backlog-0.19.0 lib/big_decimal_yaml_fix.rb
backlog-0.2.1 lib/big_decimal_yaml_fix.rb
backlog-0.20.0 lib/big_decimal_yaml_fix.rb
backlog-0.20.1 lib/big_decimal_yaml_fix.rb
backlog-0.21.0 lib/big_decimal_yaml_fix.rb
backlog-0.21.1 lib/big_decimal_yaml_fix.rb
backlog-0.21.2 lib/big_decimal_yaml_fix.rb
backlog-0.21.3 lib/big_decimal_yaml_fix.rb
backlog-0.22.0 lib/big_decimal_yaml_fix.rb
backlog-0.22.1 lib/big_decimal_yaml_fix.rb
backlog-0.23.0 lib/big_decimal_yaml_fix.rb
backlog-0.23.1 lib/big_decimal_yaml_fix.rb
backlog-0.24.0 lib/big_decimal_yaml_fix.rb
backlog-0.25.0 lib/big_decimal_yaml_fix.rb
backlog-0.26.0 lib/big_decimal_yaml_fix.rb
backlog-0.28.0 lib/big_decimal_yaml_fix.rb
backlog-0.3.0 lib/big_decimal_yaml_fix.rb
backlog-0.29.0 lib/big_decimal_yaml_fix.rb
backlog-0.3.2 lib/big_decimal_yaml_fix.rb