class Object

Public Class Methods

JSON(*args) click to toggle source
static VALUE
mimic_dump_load(int argc, VALUE *argv, VALUE self) {
    if (1 > argc) {
        rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
    } else if (T_STRING == rb_type(*argv)) {
        return mimic_load(argc, argv, self);
    } else {
        return mimic_dump(argc, argv, self);
    }
    return Qnil;
}

Public Instance Methods

to_json(*args) click to toggle source
static VALUE
mimic_object_to_json(int argc, VALUE *argv, VALUE self) {
    char                buf[4096];
    struct _Out         out;
    VALUE               rstr;
    struct _Options     copts = oj_default_options;

    out.buf = buf;
    out.end = buf + sizeof(buf) - 10;
    out.allocated = 0;
    // Have to turn off to_json to avoid the Active Support recursion problem.
    copts.to_json = No;
    // To be strict the mimic_object_to_json_options should be used but people
    // seem to prefer the option of changing that.
    //oj_dump_obj_to_json(self, &mimic_object_to_json_options, &out);
    oj_dump_obj_to_json_using_params(self, &copts, &out, argc, argv);
    if (0 == out.buf) {
        rb_raise(rb_eNoMemError, "Not enough memory.");
    }
    rstr = rb_str_new2(out.buf);
    rstr = oj_encode(rstr);
    if (out.allocated) {
        xfree(out.buf);
    }
    return rstr;
}