Sha256: a427cb213430aad87861e8b3ca57d8ee9f3326dd8b737859426bdaf9b758d701

Contents?: true

Size: 773 Bytes

Versions: 20

Compression:

Stored size: 773 Bytes

Contents

require 'bigdecimal'
require 'yaml'

class BigDecimal
  YAML_TAG = 'tag:yaml.org,2002:float'
  YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' }

  yaml_as YAML_TAG

  # This emits the number without any scientific notation.
  # This is better than self.to_f.to_s since it doesn't lose precision.
  #
  # Note that reconstituting YAML floats to native floats may lose precision.
  def to_yaml(opts = {})
    YAML.quick_emit(nil, opts) do |out|
      string = to_s
      out.scalar(YAML_TAG, YAML_MAPPING[string] || string, :plain)
    end
  end

  DEFAULT_STRING_FORMAT = 'F'
  def to_formatted_s(format = DEFAULT_STRING_FORMAT)
    _original_to_s(format)
  end
  alias_method :_original_to_s, :to_s
  alias_method :to_s, :to_formatted_s
end

Version data entries

20 entries across 20 versions & 4 rubygems

Version Path
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/activesupport-3.0.0/lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-3.0.3 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-3.0.2 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-3.0.1 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-3.0.0 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-3.0.0.rc2 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-3.0.0.rc lib/active_support/core_ext/big_decimal/conversions.rb
csd-0.1.5 lib/active_support/core_ext/big_decimal/conversions.rb
csd-0.1.4 lib/active_support/core_ext/big_decimal/conversions.rb
csd-0.1.3 lib/active_support/core_ext/big_decimal/conversions.rb
csd-0.1.2 lib/active_support/core_ext/big_decimal/conversions.rb
csd-0.1.1 lib/active_support/core_ext/big_decimal/conversions.rb
csd-0.1.0 lib/active_support/core_ext/big_decimal/conversions.rb
csd-0.0.16 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-3.0.0.beta4 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-3.0.0.beta3 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-3.0.0.beta2 lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-3.0.0.beta lib/active_support/core_ext/big_decimal/conversions.rb
activesupport-3.0.pre lib/active_support/core_ext/big_decimal/conversions.rb
recliner-0.0.1 vendor/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb