Skip to content

Commit

Permalink
document decimal_class on c ext Parser#initialize and top JSON module
Browse files Browse the repository at this point in the history
  • Loading branch information
notEthan committed May 26, 2023
1 parent 4f74d9c commit 56b40a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2812,6 +2812,9 @@ static VALUE convert_encoding(VALUE source)
* 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.
*/
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
{
Expand Down
13 changes: 13 additions & 0 deletions lib/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,19 @@
#
# ---
#
# Option +decimal_class+ (\Class) specifies which class to use when parsing
# decimal numbers. This class must accept a single string argument in its
# constructor. Defaults to Float. BigDecimal will preserve arbitrary precision.
#
# With the default, \Float:
# source = '3.141592653589793238462643383279'
# ruby = JSON.parse(source) # => 3.141592653589793
# With \BigDecimal:
# ruby = JSON.parse(source, {decimal_class: BigDecimal})
# ruby # => 0.3141592653589793238462643383279e1
#
# ---
#
# Option +create_additions+ (boolean) specifies whether to use \JSON additions in parsing.
# See {\JSON Additions}[#module-JSON-label-JSON+Additions].
#
Expand Down

0 comments on commit 56b40a6

Please sign in to comment.