summaryrefslogtreecommitdiff
path: root/ext/json/lib/json/add/bigdecimal.rb
blob: 4aafe537ab00e65315b476c48fc8659ac73ffa9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
  require 'json'
end
defined?(::BigDecimal) or require 'bigdecimal'

class BigDecimal
  def self.json_create(object)
    BigDecimal._load object['b']
  end

  def as_json(*)
    {
      JSON.create_id => self.class.name,
      'b'            => _dump,
    }
  end

  def to_json(*)
    as_json.to_json
  end
end