Skip to content

Commit 54363cb

Browse files
committed
Add more precise documentation for object_class and array_class
Fix: #419
1 parent 77e97b3 commit 54363cb

File tree

5 files changed

+117
-89
lines changed

5 files changed

+117
-89
lines changed

ext/json/ext/parser/parser.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,8 +1806,15 @@ static VALUE convert_encoding(VALUE source)
18061806
* * *create_additions*: If set to false, the Parser doesn't create
18071807
* additions even if a matching class and create_id was found. This option
18081808
* defaults to false.
1809-
* * *object_class*: Defaults to Hash
1810-
* * *array_class*: Defaults to Array
1809+
* * *object_class*: Defaults to Hash. If another type is provided, it will be used
1810+
* instead of Hash to represent JSON objects. The type must respond to
1811+
* +new+ without arguments, and return an object that respond to +[]=+.
1812+
* * *array_class*: Defaults to Array If another type is provided, it will be used
1813+
* instead of Hash to represent JSON arrays. The type must respond to
1814+
* +new+ without arguments, and return an object that respond to +<<+.
1815+
* * *decimal_class*: Specifies which class to use instead of the default
1816+
* (Float) when parsing decimal numbers. This class must accept a single
1817+
* string argument in its constructor.
18111818
*/
18121819
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
18131820
{
@@ -1909,15 +1916,15 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
19091916
}
19101917

19111918

1912-
#line 1913 "parser.c"
1919+
#line 1920 "parser.c"
19131920
enum {JSON_start = 1};
19141921
enum {JSON_first_final = 10};
19151922
enum {JSON_error = 0};
19161923

19171924
enum {JSON_en_main = 1};
19181925

19191926

1920-
#line 821 "parser.rl"
1927+
#line 828 "parser.rl"
19211928

19221929

19231930
/*
@@ -1935,16 +1942,16 @@ static VALUE cParser_parse(VALUE self)
19351942
GET_PARSER;
19361943

19371944

1938-
#line 1939 "parser.c"
1945+
#line 1946 "parser.c"
19391946
{
19401947
cs = JSON_start;
19411948
}
19421949

1943-
#line 838 "parser.rl"
1950+
#line 845 "parser.rl"
19441951
p = json->source;
19451952
pe = p + json->len;
19461953

1947-
#line 1948 "parser.c"
1954+
#line 1955 "parser.c"
19481955
{
19491956
if ( p == pe )
19501957
goto _test_eof;
@@ -1978,7 +1985,7 @@ case 1:
19781985
cs = 0;
19791986
goto _out;
19801987
tr2:
1981-
#line 813 "parser.rl"
1988+
#line 820 "parser.rl"
19821989
{
19831990
char *np = JSON_parse_value(json, p, pe, &result, 0);
19841991
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1988,7 +1995,7 @@ cs = 0;
19881995
if ( ++p == pe )
19891996
goto _test_eof10;
19901997
case 10:
1991-
#line 1992 "parser.c"
1998+
#line 1999 "parser.c"
19921999
switch( (*p) ) {
19932000
case 13: goto st10;
19942001
case 32: goto st10;
@@ -2077,7 +2084,7 @@ case 9:
20772084
_out: {}
20782085
}
20792086

2080-
#line 841 "parser.rl"
2087+
#line 848 "parser.rl"
20812088

20822089
if (cs >= JSON_first_final && p == pe) {
20832090
return result;

ext/json/ext/parser/parser.rl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,15 @@ static VALUE convert_encoding(VALUE source)
701701
* * *create_additions*: If set to false, the Parser doesn't create
702702
* additions even if a matching class and create_id was found. This option
703703
* defaults to false.
704-
* * *object_class*: Defaults to Hash
705-
* * *array_class*: Defaults to Array
704+
* * *object_class*: Defaults to Hash. If another type is provided, it will be used
705+
* instead of Hash to represent JSON objects. The type must respond to
706+
* +new+ without arguments, and return an object that respond to +[]=+.
707+
* * *array_class*: Defaults to Array If another type is provided, it will be used
708+
* instead of Hash to represent JSON arrays. The type must respond to
709+
* +new+ without arguments, and return an object that respond to +<<+.
710+
* * *decimal_class*: Specifies which class to use instead of the default
711+
* (Float) when parsing decimal numbers. This class must accept a single
712+
* string argument in its constructor.
706713
*/
707714
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
708715
{

0 commit comments

Comments
 (0)