summaryrefslogtreecommitdiff
path: root/lib/json
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2011-10-02 14:48:55 +0200
committerFlorian Frank <flori@ping.de>2011-10-02 14:48:55 +0200
commit5dcfa3711a14a6a027ce6b2b62d9117fb78da1b7 (patch)
treefdef1e294758edde001d6449645f444e19f7f76c /lib/json
parente6ada3ffde2384ff47f9e7e673a73b415846dc1f (diff)
downloadjson-5dcfa3711a14a6a027ce6b2b62d9117fb78da1b7.tar.gz
Add support for BigDecimal numbers
Diffstat (limited to 'lib/json')
-rw-r--r--lib/json/add/bigdecimal.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/json/add/bigdecimal.rb b/lib/json/add/bigdecimal.rb
new file mode 100644
index 0000000..4aafe53
--- /dev/null
+++ b/lib/json/add/bigdecimal.rb
@@ -0,0 +1,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