From c1380ba8f3ab689e0020ffe3603ac51e1885d69e Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 4 Dec 2013 20:56:59 -0800 Subject: c-ext Object#to_json passes tests now --- ext/ffi_yajl/ext/encoder/encoder.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'ext/ffi_yajl/ext/encoder') 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); } -- cgit v1.2.1