Sha256: eda7127db8566b2ef55a5fbc44886027f66e6cd3d9a0ac1c5dd25ea0366d3d3e

Contents?: true

Size: 650 Bytes

Versions: 11

Compression:

Stored size: 650 Bytes

Contents

#include "object_ext.h"

void Init_object_ext() {
  rb_define_method(rb_cObject, "to_json", (VALUE(*)(ANYARGS)) &to_json, -1);
}

/**
 * Converts this object to a string (calling #to_s), converts
 * it to a JSON string, and returns the result. This is a fallback, if no
 * special method #to_json was defined for some object.
 * _state_ is a JSON::State object, that can also be used
 * to configure the produced JSON string output further.
 */
static VALUE to_json(argc, argv, self)
  int argc;
  VALUE *argv;
  VALUE self;
{
  VALUE self_string = rb_funcall(self, rb_intern("to_s"), 0);
  return rb_funcall(self_string, rb_intern("to_json"), 0);
}

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fjson-0.0.3 ext/extensions/object_ext/object_ext.c
fjson-0.0.8 ext/extensions/object_ext/object_ext.c
fjson-0.0.2 ext/extensions/object_ext/object_ext.c
fjson-0.0.4 ext/extensions/object_ext/object_ext.c
fjson-0.0.5 ext/extensions/object_ext/object_ext.c
fjson-0.0.6 ext/extensions/object_ext/object_ext.c
fjson-0.0.7 ext/extensions/object_ext/object_ext.c
fjson-0.0.9 ext/extensions/object_ext/object_ext.c
fjson-0.1.0 ext/extensions/object_ext/object_ext.c
fjson-0.1.1 ext/extensions/object_ext/object_ext.c
fjson-0.1.2 ext/extensions/object_ext/object_ext.c