summaryrefslogtreecommitdiff
path: root/lib/json/pure/parser.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/json/pure/parser.rb')
-rw-r--r--lib/json/pure/parser.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb
index b907236..3a6343b 100644
--- a/lib/json/pure/parser.rb
+++ b/lib/json/pure/parser.rb
@@ -70,6 +70,9 @@ module JSON
# option defaults to false.
# * *object_class*: Defaults to Hash
# * *array_class*: Defaults to Array
+ # * *decimal_class*: Specifies which class to use instead of the default
+ # (Float) when parsing decimal numbers. This class must accept a single
+ # string argument in its constructor.
def initialize(source, opts = {})
opts ||= {}
source = convert_encoding source
@@ -94,6 +97,7 @@ module JSON
@create_id = @create_additions ? JSON.create_id : nil
@object_class = opts[:object_class] || Hash
@array_class = opts[:array_class] || Array
+ @decimal_class = opts[:decimal_class]
@match_string = opts[:match_string]
end
@@ -193,7 +197,7 @@ module JSON
def parse_value
case
when scan(FLOAT)
- Float(self[1])
+ @decimal_class && @decimal_class.new(self[1]) || Float(self[1])
when scan(INTEGER)
Integer(self[1])
when scan(TRUE)