diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2013-12-04 20:56:59 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2013-12-04 20:56:59 -0800 |
commit | c1380ba8f3ab689e0020ffe3603ac51e1885d69e (patch) | |
tree | ecf4e09c7ca109ef02c722060d62b7a24ab65ecc /ext | |
parent | 37b3a41a14676593c1e55cfe49cec2a91bf29ce1 (diff) | |
download | ffi-yajl-c1380ba8f3ab689e0020ffe3603ac51e1885d69e.tar.gz |
c-ext Object#to_json passes tests now
Diffstat (limited to 'ext')
-rw-r--r-- | ext/ffi_yajl/ext/encoder/encoder.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/ext/ffi_yajl/ext/encoder/encoder.c b/ext/ffi_yajl/ext/encoder/encoder.c index ade2199..004a11b 100644 --- a/ext/ffi_yajl/ext/encoder/encoder.c +++ b/ext/ffi_yajl/ext/encoder/encoder.c @@ -139,11 +139,13 @@ static VALUE rb_cString_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { return Qnil; } -// FIXME: args is a splat/varargs, does it matter? and what about the block? static VALUE rb_cObject_to_json(VALUE self, VALUE args) { - // FIXME: need to wrap quotes around this + // FIXME: probably a bit too honeybadger about ignoring the arity of this function completely + ID sym_to_s = rb_intern("to_s"); VALUE str; - str = rb_any_to_s(self); + + str = rb_funcall(self, sym_to_s, 0); + str = rb_str_concat(rb_str_concat(rb_str_new2("\""), str), rb_str_new2("\"")); return str; } @@ -171,8 +173,8 @@ void Init_encoder() { rb_define_method(rb_cBignum, "ffi_yajl", rb_cBignum_ffi_yajl, 2); rb_define_method(rb_cFloat, "ffi_yajl", rb_cFloat_ffi_yajl, 2); rb_define_method(rb_cString, "ffi_yajl", rb_cString_ffi_yajl, 2); -// FIXME: make this conditional on ActiveSupport not being defined: - rb_define_method(rb_cObject, "to_json", rb_cObject_to_json, 1); rb_define_method(rb_cObject, "ffi_yajl", rb_cObject_ffi_yajl, 2); +// FIXME: make this conditional on ActiveSupport not being defined: + rb_define_method(rb_cObject, "to_json", rb_cObject_to_json, -2); } |