Method: Oj.register_odd
- Defined in:
- ext/oj/oj.c
.register_odd(clas, create_object, create_method, *members) ⇒ Object
Registers a class as special. This is useful for working around subclasses of primitive types as is done with ActiveSupport classes. The use of this function should be limited to just classes that can not be handled in the normal way. It is not intended as a hook for changing the output of all classes as it is not optimized for large numbers of classes.
-
clas [Class_|Module] Class or Module to be made special
-
create_object [Object] object to call the create method on
-
create_method [Symbol] method on the clas that will create a new instance of the clas when given all the member values in the order specified.
-
members [Symbol_|String] methods used to get the member values from instances of the clas.
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 |
# File 'ext/oj/oj.c', line 1448 static VALUE register_odd(int argc, VALUE *argv, VALUE self) { if (3 > argc) { rb_raise(rb_eArgError, "incorrect number of arguments."); } switch (rb_type(*argv)) { case T_CLASS: case T_MODULE: break; default: rb_raise(rb_eTypeError, "expected a class or module."); break; } Check_Type(argv[2], T_SYMBOL); if (MAX_ODD_ARGS < argc - 2) { rb_raise(rb_eArgError, "too many members."); } oj_reg_odd(argv[0], argv[1], argv[2], argc - 3, argv + 3, false); return Qnil; } |