Sha256: 670a059a9e9f59f272bf7d23a953e7e36e77261678ab7ce8ae06e8f26193f817

Contents?: true

Size: 673 Bytes

Versions: 31

Compression:

Stored size: 673 Bytes

Contents

require 'bigdecimal'
require 'bigdecimal/util'
require 'yaml'

class BigDecimal
  YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' }

  def encode_with(coder)
    string = to_s
    coder.represent_scalar(nil, YAML_MAPPING[string] || string)
  end

  # Backport this method if it doesn't exist
  unless method_defined?(:to_d)
    def to_d
      self
    end
  end

  DEFAULT_STRING_FORMAT = 'F'
  def to_formatted_s(*args)
    if args[0].is_a?(Symbol)
      super
    else
      format = args[0] || DEFAULT_STRING_FORMAT
      _original_to_s(format)
    end
  end
  alias_method :_original_to_s, :to_s
  alias_method :to_s, :to_formatted_s
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
activesupport-4.0.13 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.13.rc1 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.11.1 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.12 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.11 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.10 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.10.rc2 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.10.rc1 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.9 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.8 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.7 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.6 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.6.rc3 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.6.rc2 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.6.rc1 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.5 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.4 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.4.rc1 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.0.3 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-4.1.0.beta2 lib/active_support/core_ext/big_decimal/conversions.rb