void init_kgio_connect(void) { VALUE mKgio = rb_define_module("Kgio"); VALUE cSocket = rb_const_get(rb_cObject, rb_intern("Socket")); VALUE mSocketMethods = rb_const_get(mKgio, rb_intern("SocketMethods")); VALUE cKgio_Socket, cTCPSocket, cUNIXSocket; /* * Document-class: Kgio::Socket * * A generic socket class with Kgio::SocketMethods included. * This is returned by all Kgio methods that accept(2) a connected * stream socket. */ cKgio_Socket = rb_define_class_under(mKgio, "Socket", cSocket); rb_include_module(cKgio_Socket, mSocketMethods); rb_define_singleton_method(cKgio_Socket, "new", kgio_new, -1); rb_define_singleton_method(cKgio_Socket, "connect", kgio_connect, 1); rb_define_singleton_method(cKgio_Socket, "start", kgio_start, 1); #if defined(MSG_FASTOPEN) && defined(KGIO_HAVE_THREAD_CALL_WITHOUT_GVL) rb_define_method(cKgio_Socket, "kgio_fastopen", fastopen, 2); #endif /* * Document-class: Kgio::TCPSocket * * Kgio::TCPSocket should be used in place of the plain TCPSocket * when kgio_* methods are needed. */ cTCPSocket = rb_const_get(rb_cObject, rb_intern("TCPSocket")); cTCPSocket = rb_define_class_under(mKgio, "TCPSocket", cTCPSocket); rb_include_module(cTCPSocket, mSocketMethods); rb_define_singleton_method(cTCPSocket, "new", kgio_tcp_connect, 2); rb_define_singleton_method(cTCPSocket, "start", kgio_tcp_start, 2); /* * Document-class: Kgio::UNIXSocket * * Kgio::UNIXSocket should be used in place of the plain UNIXSocket * when kgio_* methods are needed. */ cUNIXSocket = rb_const_get(rb_cObject, rb_intern("UNIXSocket")); cUNIXSocket = rb_define_class_under(mKgio, "UNIXSocket", cUNIXSocket); rb_include_module(cUNIXSocket, mSocketMethods); rb_define_singleton_method(cUNIXSocket, "new", kgio_unix_connect, 1); rb_define_singleton_method(cUNIXSocket, "start", kgio_unix_start, 1); init_sock_for_fd(); }
void init_pg_result() { rb_cPGresult = rb_define_class_under( rb_mPG, "Result", rb_cObject ); rb_include_module(rb_cPGresult, rb_mEnumerable); rb_include_module(rb_cPGresult, rb_mPGconstants); /****** PG::Result INSTANCE METHODS: libpq ******/ rb_define_method(rb_cPGresult, "result_status", pgresult_result_status, 0); rb_define_method(rb_cPGresult, "res_status", pgresult_res_status, 1); rb_define_method(rb_cPGresult, "error_message", pgresult_error_message, 0); rb_define_alias( rb_cPGresult, "result_error_message", "error_message"); rb_define_method(rb_cPGresult, "error_field", pgresult_error_field, 1); rb_define_alias( rb_cPGresult, "result_error_field", "error_field" ); rb_define_method(rb_cPGresult, "clear", pg_result_clear, 0); rb_define_method(rb_cPGresult, "check", pg_result_check, 0); rb_define_alias (rb_cPGresult, "check_result", "check"); rb_define_method(rb_cPGresult, "ntuples", pgresult_ntuples, 0); rb_define_alias(rb_cPGresult, "num_tuples", "ntuples"); rb_define_method(rb_cPGresult, "nfields", pgresult_nfields, 0); rb_define_alias(rb_cPGresult, "num_fields", "nfields"); rb_define_method(rb_cPGresult, "fname", pgresult_fname, 1); rb_define_method(rb_cPGresult, "fnumber", pgresult_fnumber, 1); rb_define_method(rb_cPGresult, "ftable", pgresult_ftable, 1); rb_define_method(rb_cPGresult, "ftablecol", pgresult_ftablecol, 1); rb_define_method(rb_cPGresult, "fformat", pgresult_fformat, 1); rb_define_method(rb_cPGresult, "ftype", pgresult_ftype, 1); rb_define_method(rb_cPGresult, "fmod", pgresult_fmod, 1); rb_define_method(rb_cPGresult, "fsize", pgresult_fsize, 1); rb_define_method(rb_cPGresult, "getvalue", pgresult_getvalue, 2); rb_define_method(rb_cPGresult, "getisnull", pgresult_getisnull, 2); rb_define_method(rb_cPGresult, "getlength", pgresult_getlength, 2); rb_define_method(rb_cPGresult, "nparams", pgresult_nparams, 0); rb_define_method(rb_cPGresult, "paramtype", pgresult_paramtype, 1); rb_define_method(rb_cPGresult, "cmd_status", pgresult_cmd_status, 0); rb_define_method(rb_cPGresult, "cmd_tuples", pgresult_cmd_tuples, 0); rb_define_alias(rb_cPGresult, "cmdtuples", "cmd_tuples"); rb_define_method(rb_cPGresult, "oid_value", pgresult_oid_value, 0); /****** PG::Result INSTANCE METHODS: other ******/ rb_define_method(rb_cPGresult, "[]", pgresult_aref, 1); rb_define_method(rb_cPGresult, "each", pgresult_each, 0); rb_define_method(rb_cPGresult, "fields", pgresult_fields, 0); rb_define_method(rb_cPGresult, "values", pgresult_values, 0); rb_define_method(rb_cPGresult, "column_values", pgresult_column_values, 1); rb_define_method(rb_cPGresult, "field_values", pgresult_field_values, 1); }
void Init_Enumerator(void) { rb_define_method(rb_mKernel, "to_enum", obj_to_enum, -1); rb_define_method(rb_mKernel, "enum_for", obj_to_enum, -1); rb_define_method(rb_mEnumerable, "each_slice", enum_each_slice, 1); rb_define_method(rb_mEnumerable, "each_cons", enum_each_cons, 1); rb_define_method(rb_mEnumerable, "each_with_object", enum_each_with_object, 1); rb_cEnumerator = rb_define_class("Enumerator", rb_cObject); rb_include_module(rb_cEnumerator, rb_mEnumerable); rb_define_alloc_func(rb_cEnumerator, enumerator_allocate); rb_define_method(rb_cEnumerator, "initialize", enumerator_initialize, -1); rb_define_method(rb_cEnumerator, "initialize_copy", enumerator_init_copy, 1); rb_define_method(rb_cEnumerator, "each", enumerator_each, 0); rb_define_method(rb_cEnumerator, "each_with_index", enumerator_with_index, 0); rb_define_method(rb_cEnumerator, "each_with_object", enumerator_with_object, 1); rb_define_method(rb_cEnumerator, "with_index", enumerator_with_index, 0); rb_define_method(rb_cEnumerator, "with_object", enumerator_with_object, 1); rb_define_method(rb_cEnumerator, "next", enumerator_next, 0); rb_define_method(rb_cEnumerator, "rewind", enumerator_rewind, 0); rb_eStopIteration = rb_define_class("StopIteration", rb_eIndexError); /* Generator */ rb_cGenerator = rb_define_class_under(rb_cEnumerator, "Generator", rb_cObject); rb_include_module(rb_cGenerator, rb_mEnumerable); rb_define_alloc_func(rb_cGenerator, generator_allocate); rb_define_method(rb_cGenerator, "initialize", generator_initialize, -1); rb_define_method(rb_cGenerator, "initialize_copy", generator_init_copy, 1); rb_define_method(rb_cGenerator, "each", generator_each, 0); /* Yielder */ rb_cYielder = rb_define_class_under(rb_cEnumerator, "Yielder", rb_cObject); rb_define_alloc_func(rb_cYielder, yielder_allocate); rb_define_method(rb_cYielder, "initialize", yielder_initialize, 0); rb_define_method(rb_cYielder, "yield", yielder_yield, -2); rb_define_method(rb_cYielder, "<<", yielder_yield, -2); sym_each = ID2SYM(rb_intern("each")); id_rewind = rb_intern("rewind"); rb_provide("enumerator.so"); /* for backward compatibility */ }
void rb_grn_init_patricia_trie_cursor (VALUE mGrn) { rb_cGrnPatriciaTrieCursor = rb_define_class_under(mGrn, "PatriciaTrieCursor", rb_cGrnTableCursor); rb_include_module(rb_cGrnPatriciaTrieCursor, rb_mGrnTableCursorKeySupport); }
void Init_do_sqlite3_ext() { rb_require("bigdecimal"); rb_require("date"); // Get references classes needed for Date/Time parsing rb_cDate = CONST_GET(rb_mKernel, "Date"); rb_cDateTime = CONST_GET(rb_mKernel, "DateTime"); rb_cTime = CONST_GET(rb_mKernel, "Time"); rb_cBigDecimal = CONST_GET(rb_mKernel, "BigDecimal"); rb_funcall(rb_mKernel, rb_intern("require"), 1, rb_str_new2("data_objects")); #ifdef RUBY_LESS_THAN_186 ID_NEW_DATE = rb_intern("new0"); #else ID_NEW_DATE = rb_intern("new!"); #endif ID_RATIONAL = rb_intern("Rational"); ID_LOGGER = rb_intern("logger"); ID_DEBUG = rb_intern("debug"); ID_LEVEL = rb_intern("level"); // Get references to the DataObjects module and its classes mDO = CONST_GET(rb_mKernel, "DataObjects"); cDO_Quoting = CONST_GET(mDO, "Quoting"); cDO_Connection = CONST_GET(mDO, "Connection"); cDO_Command = CONST_GET(mDO, "Command"); cDO_Result = CONST_GET(mDO, "Result"); cDO_Reader = CONST_GET(mDO, "Reader"); // Initialize the DataObjects::Sqlite3 module, and define its classes mSqlite3 = rb_define_module_under(mDO, "Sqlite3"); eSqlite3Error = rb_define_class("Sqlite3Error", rb_eStandardError); cConnection = SQLITE3_CLASS("Connection", cDO_Connection); rb_define_method(cConnection, "initialize", cConnection_initialize, 1); rb_define_method(cConnection, "dispose", cConnection_dispose, 0); cCommand = SQLITE3_CLASS("Command", cDO_Command); rb_include_module(cCommand, cDO_Quoting); rb_define_method(cCommand, "set_types", cCommand_set_types, 1); rb_define_method(cCommand, "execute_non_query", cCommand_execute_non_query, -1); rb_define_method(cCommand, "execute_reader", cCommand_execute_reader, -1); rb_define_method(cCommand, "quote_boolean", cCommand_quote_boolean, 1); rb_define_method(cCommand, "quote_string", cCommand_quote_string, 1); cResult = SQLITE3_CLASS("Result", cDO_Result); cReader = SQLITE3_CLASS("Reader", cDO_Reader); rb_define_method(cReader, "close", cReader_close, 0); rb_define_method(cReader, "next!", cReader_next, 0); rb_define_method(cReader, "values", cReader_values, 0); rb_define_method(cReader, "fields", cReader_fields, 0); rb_define_method(cReader, "field_count", cReader_field_count, 0); rb_define_method(cReader, "row_count", cReader_row_count, 0); }
void init_kgio_tryopen(void) { VALUE mKgio = rb_define_module("Kgio"); VALUE mPipeMethods = rb_const_get(mKgio, rb_intern("PipeMethods")); VALUE cFile; VALUE tmp; VALUE *ptr; long len; id_path = rb_intern("path"); id_for_fd = rb_intern("for_fd"); id_to_path = rb_intern("to_path"); /* * Document-class: Kgio::File * * This subclass of the core File class adds the "tryopen" singleton * method for opening files. A single "tryopen" and check for the * return value may be used to avoid unnecessary stat(2) syscalls * or File.open exceptions when checking for the existence of a file * and opening it. */ cFile = rb_define_class_under(mKgio, "File", rb_cFile); rb_define_singleton_method(cFile, "tryopen", s_tryopen, -1); rb_include_module(cFile, mPipeMethods); if (!rb_funcall(cFile, rb_intern("method_defined?"), 1, ID2SYM(id_to_path))) rb_define_alias(cFile, "to_path", "path"); errno2sym = st_init_numtable(); tmp = rb_funcall(rb_mErrno, rb_intern("constants"), 0); ptr = RARRAY_PTR(tmp); len = RARRAY_LEN(tmp); for (; --len >= 0; ptr++) { VALUE error; ID const_id; switch (TYPE(*ptr)) { case T_SYMBOL: const_id = SYM2ID(*ptr); break; case T_STRING: const_id = rb_intern(RSTRING_PTR(*ptr)); break; default: rb_bug("constant not a symbol or string"); } error = rb_const_get(rb_mErrno, const_id); if ((TYPE(error) != T_CLASS) || !rb_const_defined(error, rb_intern("Errno"))) continue; error = rb_const_get(error, rb_intern("Errno")); switch (TYPE(error)) { case T_FIXNUM: case T_BIGNUM: st_insert(errno2sym, (st_data_t)NUM2INT(error), ID2SYM(const_id)); } } }
void init_ruby_class() { #if 0 // For documentation using YARD VALUE opencv = rb_define_module("OpenCV"); VALUE cvseq = rb_define_class_under(opencv, "CvSeq"); VALUE curve = rb_define_module_under(opencv, "Curve"); VALUE pointset = rb_define_module_under(opencv, "PointSet"); #endif if (rb_klass) return; VALUE opencv = rb_module_opencv(); VALUE cvseq = cCvSeq::rb_class(); VALUE curve = mCurve::rb_module(); VALUE pointset = mPointSet::rb_module(); rb_klass = rb_define_class_under(opencv, "CvContour", cvseq); rb_include_module(rb_klass, curve); rb_include_module(rb_klass, pointset); rb_define_alloc_func(rb_klass, rb_allocate); VALUE approx_option = rb_hash_new(); rb_define_const(rb_klass, "APPROX_OPTION", approx_option); rb_hash_aset(approx_option, ID2SYM(rb_intern("method")), INT2FIX(CV_POLY_APPROX_DP)); rb_hash_aset(approx_option, ID2SYM(rb_intern("accuracy")), rb_float_new(1.0)); rb_hash_aset(approx_option, ID2SYM(rb_intern("recursive")), Qfalse); rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1); rb_define_method(rb_klass, "rect", RUBY_METHOD_FUNC(rb_rect), 0); rb_define_method(rb_klass, "color", RUBY_METHOD_FUNC(rb_color), 0); rb_define_method(rb_klass, "color=", RUBY_METHOD_FUNC(rb_set_color), 1); rb_define_method(rb_klass, "reserved", RUBY_METHOD_FUNC(rb_reserved), 0); rb_define_method(rb_klass, "approx_poly", RUBY_METHOD_FUNC(rb_approx_poly), -1); rb_define_alias(rb_klass, "approx", "approx_poly"); rb_define_method(rb_klass, "bounding_rect", RUBY_METHOD_FUNC(rb_bounding_rect), 0); rb_define_method(rb_klass, "create_tree", RUBY_METHOD_FUNC(rb_create_tree), -1); rb_define_method(rb_klass, "in?", RUBY_METHOD_FUNC(rb_in_q), 1); rb_define_method(rb_klass, "measure_distance", RUBY_METHOD_FUNC(rb_measure_distance), 1); rb_define_method(rb_klass, "point_polygon_test", RUBY_METHOD_FUNC(rb_point_polygon_test), 2); rb_define_method(rb_klass, "match_shapes", RUBY_METHOD_FUNC(rb_match_shapes), -1); }
void Init_Result (VALUE mXmms) { cResult = rb_define_class_under (mXmms, "Result", rb_cObject); /* ugh, we have to define the "new" method, * so we can remove it again :( */ rb_define_singleton_method (cResult, "new", NULL, 0); rb_undef_method (rb_singleton_class (cResult), "new"); rb_define_method (cResult, "notifier", c_notifier_set, 0); rb_define_method (cResult, "wait", c_wait, 0); rb_define_method (cResult, "value", c_value_get, 0); rb_define_method (cResult, "error?", c_is_error, 0); rb_define_method (cResult, "error", c_get_error, 0); cBroadcastResult = rb_define_class_under (mXmms, "BroadcastResult", cResult); rb_define_method (cBroadcastResult, "disconnect", c_disconnect, 0); cSignalResult = rb_define_class_under (mXmms, "SignalResult", cResult); rb_define_method (cSignalResult, "disconnect", c_disconnect, 0); eResultError = rb_define_class_under (cResult, "ResultError", rb_eStandardError); eValueError = rb_define_class_under (cResult, "ValueError", eResultError); cDict = rb_define_class_under (mXmms, "Dict", rb_cObject); #ifdef HAVE_RB_PROTECT_INSPECT rb_define_method (cDict, "inspect", c_dict_inspect, 0); #endif /* HAVE_RB_PROTECT_INSPECT */ rb_define_method (cDict, "size", c_dict_size, 0); rb_define_method (cDict, "empty?", c_dict_empty, 0); rb_define_method (cDict, "[]", c_dict_aref, 1); rb_define_method (cDict, "has_key?", c_dict_has_key, 1); rb_define_method (cDict, "each", c_dict_each, 0); rb_define_method (cDict, "each_key", c_dict_each_key, 0); rb_define_method (cDict, "each_value", c_dict_each_value, 0); rb_define_alias (cDict, "length", "size"); rb_define_alias (cDict, "include?", "has_key?"); rb_define_alias (cDict, "key?", "has_key?"); rb_define_alias (cDict, "member?", "has_key?"); rb_define_alias (cDict, "each_pair", "each"); rb_include_module (cDict, rb_mEnumerable); cRawDict = rb_define_class_under (mXmms, "RawDict", cDict); rb_define_method (cRawDict, "to_propdict", c_raw_dict_to_propdict, -1); }
void rb_grn_init_double_array_trie_cursor (VALUE mGrn) { rb_cGrnDoubleArrayTrieCursor = rb_define_class_under(mGrn, "DoubleArrayTrieCursor", rb_cGrnTableCursor); rb_include_module(rb_cGrnDoubleArrayTrieCursor, rb_mGrnTableCursorKeySupport); }
VALUE Init_ct_move(void) { cCtMove = rb_define_class("CtMove", rb_cObject); rb_include_module(cCtMove, rb_mComparable); rb_define_method(cCtMove, "inspect", ct_move_inspect_rb, 0); rb_define_method(cCtMove, "<=>", ct_move_compare_rb, 1); return cCtMove; }
void _init_type_array() { rb_cTypeArray = rb_define_class("TypeArray", rb_cObject); rb_include_module(rb_cTypeArray, rb_mEnumerable); rb_type_array_intern_aget = rb_intern("[]"); rb_type_array_intern_aset = rb_intern("[]="); rb_type_array_intern_superclass = rb_intern("superclass"); rb_cInt8Array = rb_define_class("Int8Array", rb_cTypeArray); rb_cUInt8Array = rb_define_class("UInt8Array", rb_cTypeArray); rb_cInt16Array = rb_define_class("Int16Array", rb_cTypeArray); rb_cUInt16Array = rb_define_class("UInt16Array", rb_cTypeArray); rb_cInt32Array = rb_define_class("Int32Array", rb_cTypeArray); rb_cUInt32Array = rb_define_class("UInt32Array", rb_cTypeArray); rb_cFloat32Array = rb_define_class("Float32Array", rb_cTypeArray); rb_cFloat64Array = rb_define_class("Float64Array", rb_cTypeArray); rb_cStructArray = rb_define_class("StructArray", rb_cTypeArray); rb_define_const(rb_cInt8Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(signed char))); rb_define_const(rb_cUInt8Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(unsigned char))); rb_define_const(rb_cInt16Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(short))); rb_define_const(rb_cUInt16Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(unsigned short))); rb_define_const(rb_cInt32Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(int))); rb_define_const(rb_cUInt32Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(unsigned int))); rb_define_const(rb_cFloat32Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(float))); rb_define_const(rb_cFloat64Array, "BYTES_PER_ELEMENT", ULONG2NUM(sizeof(double))); rb_define_const(rb_cStructArray, "BYTES_PER_ELEMENT", INT2NUM(0)); rb_require("struct_type"); rb_cStructType = rb_const_get(rb_cObject, rb_intern("StructType")); rb_define_singleton_method(rb_cTypeArray, "new", rb_type_array_s_new, -1); rb_define_singleton_method(rb_cStructArray, "new", rb_struct_array_s_new, -1); rb_define_method(rb_cTypeArray, "byte_length", rb_type_array_byte_length, 0); rb_define_method(rb_cTypeArray, "length", rb_type_array_length, 0); rb_define_method(rb_cTypeArray, "buffer", rb_type_array_buffer, 0); rb_define_method(rb_cTypeArray, "byte_offset", rb_type_array_byte_offset, 0); rb_define_method(rb_cTypeArray, "to_s", rb_type_array_to_s, 0); rb_define_method(rb_cTypeArray, "[]=", rb_type_array_aset, 2); rb_define_method(rb_cTypeArray, "[]", rb_type_array_aget, 1); rb_define_method(rb_cTypeArray, "mul", rb_type_array_mul, -1); rb_define_method(rb_cTypeArray, "plus", rb_type_array_plus, -1); rb_define_method(rb_cTypeArray, "minus", rb_type_array_minus, -1); rb_define_method(rb_cTypeArray, "div", rb_type_array_div, -1); rb_define_method(rb_cTypeArray, "eql", rb_type_array_eql, 2); rb_define_method(rb_cTypeArray, "each", rb_type_array_each, 0); rb_define_method(rb_cStructArray, "struct_type", rb_type_array_struct_type, 0); rb_undef(rb_cStructArray, rb_intern("mul")); rb_undef(rb_cStructArray, rb_intern("plus")); rb_undef(rb_cStructArray, rb_intern("minus")); rb_undef(rb_cStructArray, rb_intern("div")); rb_undef(rb_cStructArray, rb_intern("eql")); }
void init_erlix_pid(VALUE erlix){ erlix_cErlixPid=rb_define_class_under(erlix,"Pid",rb_cObject); rb_define_alloc_func(erlix_cErlixPid,erlix_pid_alloc); rb_define_method(erlix_cErlixPid,"initialize",erlix_pid_init,1); rb_define_method(erlix_cErlixPid,"inspect",erlix_pid_inspect,0); rb_define_method(erlix_cErlixPid,"etype",erlix_pid_etype,0); rb_include_module(erlix_cErlixPid,erlix_mErlixTerm); }
/* call-seq: * inherit(*classes) -> self * * Make copies of all given +classes+ as modules, and includes * those modules in the receiver. Raises +TypeError+ if any of the * +classes+ is not a Class or is not compatible with the receiver. */ static VALUE evilr_inherit(int argc, VALUE* argv, VALUE klass) { int i; for(i = 0; i < argc; i++) { evilr__check_compatible_classes(klass, argv[i]); rb_include_module(klass, evilr_to_module(argv[i])); } return klass; }
void rb_grn_init_table_key_support (VALUE mGrn) { rb_mGrnTableKeySupport = rb_define_module_under(rb_cGrnTable, "KeySupport"); rb_include_module(rb_mGrnTableKeySupport, rb_mGrnEncodingSupport); rb_define_method(rb_mGrnTableKeySupport, "inspect", rb_grn_table_key_support_inspect, 0); rb_define_method(rb_mGrnTableKeySupport, "add", rb_grn_table_key_support_add, -1); rb_define_method(rb_mGrnTableKeySupport, "id", rb_grn_table_key_support_get_id, -1); rb_define_method(rb_mGrnTableKeySupport, "key", rb_grn_table_key_support_get_key, 1); rb_define_method(rb_mGrnTableKeySupport, "has_key?", rb_grn_table_key_support_has_key, 1); rb_define_method(rb_mGrnTableKeySupport, "delete", rb_grn_table_key_support_delete, -1); rb_define_method(rb_mGrnTableKeySupport, "[]", rb_grn_table_key_support_array_reference, 1); rb_define_method(rb_mGrnTableKeySupport, "[]=", rb_grn_table_key_support_array_set, 2); rb_define_method(rb_mGrnTableKeySupport, "column_value", rb_grn_table_key_support_get_column_value, -1); rb_define_method(rb_mGrnTableKeySupport, "set_column_value", rb_grn_table_key_support_set_column_value, -1); rb_define_method(rb_mGrnTableKeySupport, "value", rb_grn_table_key_support_get_value, -1); rb_define_method(rb_mGrnTableKeySupport, "set_value", rb_grn_table_key_support_set_value, -1); rb_define_method(rb_mGrnTableKeySupport, "default_tokenizer", rb_grn_table_key_support_get_default_tokenizer, 0); rb_define_method(rb_mGrnTableKeySupport, "default_tokenizer=", rb_grn_table_key_support_set_default_tokenizer, 1); rb_define_method(rb_mGrnTableKeySupport, "normalizer", rb_grn_table_key_support_get_normalizer, 0); rb_define_method(rb_mGrnTableKeySupport, "normalizer=", rb_grn_table_key_support_set_normalizer, 1); rb_define_method(rb_mGrnTableKeySupport, "normalize_key?", rb_grn_table_key_support_normalize_key_p, 0); rb_define_method(rb_mGrnTableKeySupport, "support_key?", rb_grn_table_key_support_support_key_p, 0); rb_define_method(rb_mGrnTableKeySupport, "tokenize", rb_grn_table_key_support_tokenize, -1); }
void init_erlix_atom(){ erlix_cErlixAtom=rb_define_class("ErlixAtom",rb_cObject); rb_define_alloc_func(erlix_cErlixAtom,erlix_atom_alloc); rb_define_method(erlix_cErlixAtom,"initialize",erlix_atom_init,1); rb_define_method(erlix_cErlixAtom,"size",erlix_atom_size,0); rb_define_method(erlix_cErlixAtom,"etype",erlix_atom_etype,0); rb_define_method(erlix_cErlixAtom,"inspect",erlix_atom_inspect,0); rb_include_module(erlix_cErlixAtom,erlix_mErlixTerm); }
void rb_grn_init_index_cursor (VALUE mGrn) { rb_cGrnIndexCursor = rb_define_class_under(mGrn, "IndexCursor", rb_cGrnObject); rb_define_alloc_func(rb_cGrnIndexCursor, rb_grn_object_alloc); rb_include_module(rb_cGrnIndexCursor, rb_mEnumerable); rb_define_method(rb_cGrnIndexCursor, "next", rb_grn_index_cursor_next, 0); rb_define_method(rb_cGrnIndexCursor, "each", rb_grn_index_cursor_each, 0); }
static VALUE asteroid_s_run(VALUE Self, VALUE Host, VALUE Port, VALUE Module){ char *host = StringValuePtr(Host); int port = FIX2INT(Port); epoll_fd = asteroid_poll_create(1024); if(epoll_fd == -1) runtime_error(); struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = inet_addr(host); int s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP), c, one = 1; if(s == -1) runtime_error(); fcntl(s, F_SETFL, fcntl(s, F_GETFL, 0) | O_NONBLOCK); setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); nosigpipe(s); if(bind(s, (struct sockaddr*)&addr, sizeof(addr)) != 0) runtime_error(); if(listen(s, MAX_CONNECTION) != 0) runtime_error(); if(rb_block_given_p()) rb_yield(Qnil); VALUE Class = rb_define_class_under(Asteroid, "Server", rb_cObject); rb_define_method(Class, "send_data", asteroid_server_send_data, 1); rb_define_method(Class, "write_and_close", asteroid_server_write_and_close, 0); rb_include_module(Class, Module); // Mac OS X, Fedora needs explicit rb_thread_schedule call. for(running = 1; running; rb_thread_schedule()){ socklen_t len = sizeof(addr); while((c = accept(s, (struct sockaddr*)&addr, &len)) != -1){ printf("A New client connected here\n"); fcntl(c, F_SETFL, fcntl(c, F_GETFL, 0) | O_NONBLOCK); asteroid_poll_event_t event; memset(&event, 0, sizeof(event)); if(asteroid_poll_add(epoll_fd, &event, c) == -1) runtime_error(); // instantiate server class which responds to client. VALUE Server = rb_class_new_instance(0, NULL, Class); rb_iv_set(Server, "@fd", rb_fix_new(c)); rb_hash_aset(clients, rb_fix_new(c), Server); if(rb_respond_to(Server, rb_intern("post_init"))){ rb_funcall(Server, rb_intern("post_init"), 0); } } if(dispatch() != 0) asteroid_s_stop(Asteroid); // You must call them to give a chance for ruby to handle system events. // CHECK_INTS; } rb_iterate(rb_each, clients, close_socket_proc, Qnil); rb_funcall(clients, rb_intern("clear"), 0); close(s); close(epoll_fd); return Qnil; }
void Init_switch() { cSwitch = rb_define_class_under( mTrema, "Switch", rb_cObject ); rb_include_module( cSwitch, mLogger ); rb_define_method( cSwitch, "run!", switch_run, 0 ); rb_define_method( cSwitch, "send_message", switch_send_message, 1 ); rb_define_private_method( cSwitch, "start_chibach", switch_start_chibach, 0 ); rb_require( "trema/switch" ); }
void Init_rpmmi(void) { rpmmiClass = rb_define_class("Mi", rb_cObject); if (_debug) fprintf(stderr, "==> %s() rpmmiClass 0x%lx\n", __FUNCTION__, rpmmiClass); rb_include_module(rpmmiClass, rb_mEnumerable); rb_define_singleton_method(rpmmiClass, "new", rpmmi_new, -1); initProperties(rpmmiClass); initMethods(rpmmiClass); }
void init_erlix_uint(VALUE erlix){ erlix_cErlixUInt=rb_define_class_under(erlix,"UInt",rb_cObject); rb_define_alloc_func(erlix_cErlixUInt,erlix_uint_alloc); rb_define_method(erlix_cErlixUInt,"initialize",erlix_uint_init,1); rb_define_method(erlix_cErlixUInt,"to_i",erlix_uint_to_fix,0); rb_define_method(erlix_cErlixUInt,"inspect",erlix_uint_inspect,0); rb_define_method(erlix_cErlixUInt,"etype",erlix_uint_etype,0); rb_include_module(erlix_cErlixUInt,erlix_mErlixTerm); }
void Init_acts_as_foo() { ActsAsFoo = rb_define_module("ActsAsFoo"); rb_define_method(ActsAsFoo, "foo?", rb_ActsAsFoo_foo_q, 0); rb_define_singleton_method(ActsAsFoo, "included", rb_ActsAsFoo_included, 1); ActsAsFoo_ClassMethods = rb_define_module_under(ActsAsFoo, "ClassMethods"); rb_define_method(ActsAsFoo_ClassMethods, "foo?", rb_ActsAsFoo_foo_q, 0); rb_include_module(Bar, ActsAsFoo); // call ActsAsFoo.included(Bar) manually since rb_include_module doesn't rb_funcall(ActsAsFoo, rb_intern("included"), 1, Bar); }
void pg_define_coder( const char *name, void *func, VALUE base_klass, VALUE nsp ) { VALUE cfunc_obj = Data_Wrap_Struct( rb_cObject, NULL, NULL, func ); VALUE coder_klass = rb_define_class_under( nsp, name, base_klass ); if( nsp==rb_mPG_BinaryEncoder || nsp==rb_mPG_BinaryDecoder ) rb_include_module( coder_klass, rb_mPG_BinaryFormatting ); rb_define_const( coder_klass, "CFUNC", cfunc_obj ); RB_GC_GUARD(cfunc_obj); }
void Init_binding_of_caller() { VALUE mBindingOfCaller = rb_define_module("BindingOfCaller"); rb_define_method(mBindingOfCaller, "of_caller", binding_of_caller, 1); rb_define_method(mBindingOfCaller, "frame_count", frame_count, 0); rb_define_method(mBindingOfCaller, "frame_type", frame_type, 0); rb_define_method(mBindingOfCaller, "frame_description", frame_description, 0); rb_define_method(mBindingOfCaller, "callers", callers, 0); rb_include_module(rb_cBinding, mBindingOfCaller); }
void rb_grn_init_hash (VALUE mGrn) { rb_cGrnHash = rb_define_class_under(mGrn, "Hash", rb_cGrnTable); rb_include_module(rb_cGrnHash, rb_mGrnTableKeySupport); rb_define_singleton_method(rb_cGrnHash, "create", rb_grn_hash_s_create, -1); rb_define_method(rb_cGrnHash, "search", rb_grn_hash_search, -1); }
void Init_Enumerator(void) { rb_objc_define_method(rb_mKernel, "to_enum", obj_to_enum, -1); rb_objc_define_method(rb_mKernel, "enum_for", obj_to_enum, -1); rb_cEnumerator = rb_define_class("Enumerator", rb_cObject); rb_include_module(rb_cEnumerator, rb_mEnumerable); rb_objc_define_method(*(VALUE *)rb_cEnumerator, "alloc", enumerator_allocate, 0); rb_objc_define_method(rb_cEnumerator, "initialize", enumerator_initialize, -1); rb_objc_define_method(rb_cEnumerator, "initialize_copy", enumerator_init_copy, 1); rb_objc_define_method(rb_cEnumerator, "each", enumerator_each, 0); rb_objc_define_method(rb_cEnumerator, "each_with_index", enumerator_each_with_index, 0); rb_objc_define_method(rb_cEnumerator, "each_with_object", enumerator_with_object, 1); rb_objc_define_method(rb_cEnumerator, "with_index", enumerator_with_index, -1); rb_objc_define_method(rb_cEnumerator, "with_object", enumerator_with_object, 1); rb_objc_define_method(rb_cEnumerator, "next", enumerator_next, 0); rb_objc_define_method(rb_cEnumerator, "rewind", enumerator_rewind, 0); rb_objc_define_method(rb_cEnumerator, "inspect", enumerator_inspect, 0); rb_eStopIteration = rb_define_class("StopIteration", rb_eIndexError); /* Generator */ rb_cGenerator = rb_define_class_under(rb_cEnumerator, "Generator", rb_cObject); rb_include_module(rb_cGenerator, rb_mEnumerable); rb_objc_define_method(*(VALUE *)rb_cGenerator, "alloc", generator_allocate, 0); rb_objc_define_method(rb_cGenerator, "initialize", generator_initialize, -1); rb_objc_define_method(rb_cGenerator, "initialize_copy", generator_init_copy, 1); rb_objc_define_method(rb_cGenerator, "each", generator_each, 0); /* Yielder */ rb_cYielder = rb_define_class_under(rb_cEnumerator, "Yielder", rb_cObject); rb_objc_define_method(*(VALUE *)rb_cYielder, "alloc", yielder_allocate, 0); rb_objc_define_method(rb_cYielder, "initialize", yielder_initialize, 0); rb_objc_define_method(rb_cYielder, "yield", yielder_yield, -2); rb_objc_define_method(rb_cYielder, "<<", yielder_yield_push, -2); sym_each = ID2SYM(rb_intern("each")); }
VALUE build_class_from_descriptor(Descriptor* desc) { const char *name; VALUE klass; if (desc->layout == NULL) { desc->layout = create_layout(desc->msgdef); } if (desc->fill_method == NULL) { desc->fill_method = new_fillmsg_decodermethod(desc, &desc->fill_method); } name = upb_msgdef_fullname(desc->msgdef); if (name == NULL) { rb_raise(rb_eRuntimeError, "Descriptor does not have assigned name."); } klass = rb_define_class_id( // Docs say this parameter is ignored. User will assign return value to // their own toplevel constant class name. rb_intern("Message"), rb_cObject); rb_ivar_set(klass, descriptor_instancevar_interned, get_def_obj(desc->msgdef)); rb_define_alloc_func(klass, Message_alloc); rb_require("google/protobuf/message_exts"); rb_include_module(klass, rb_eval_string("::Google::Protobuf::MessageExts")); rb_extend_object( klass, rb_eval_string("::Google::Protobuf::MessageExts::ClassMethods")); rb_define_method(klass, "method_missing", Message_method_missing, -1); rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing, -1); rb_define_method(klass, "initialize", Message_initialize, -1); rb_define_method(klass, "dup", Message_dup, 0); // Also define #clone so that we don't inherit Object#clone. rb_define_method(klass, "clone", Message_dup, 0); rb_define_method(klass, "==", Message_eq, 1); rb_define_method(klass, "hash", Message_hash, 0); rb_define_method(klass, "to_h", Message_to_h, 0); rb_define_method(klass, "to_hash", Message_to_h, 0); rb_define_method(klass, "inspect", Message_inspect, 0); rb_define_method(klass, "[]", Message_index, 1); rb_define_method(klass, "[]=", Message_index_set, 2); rb_define_singleton_method(klass, "decode", Message_decode, 1); rb_define_singleton_method(klass, "encode", Message_encode, 1); rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1); rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1); rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0); return klass; }
Init_minidb() { rb_cMiniDB = rb_define_class("MiniDB", rb_cObject); rb_define_alloc_func(rb_cMiniDB, minidb_alloc); rb_define_method(rb_cMiniDB, "initialize", minidb_init, 1); rb_define_method(rb_cMiniDB, "[]", minidb_get, 1); rb_define_method(rb_cMiniDB, "[]=", minidb_set, 2); rb_define_method(rb_cMiniDB, "close", minidb_close, 0); rb_define_method(rb_cMiniDB, "each", minidb_each, 0); rb_include_module(rb_cMiniDB, rb_mEnumerable); }
/* --- Class initialization */ void Init_rpmhdr(void) { rpmhdrClass = rb_define_class("Hdr", rb_cObject); if (_debug) fprintf(stderr, "==> %s() rpmhdrClass 0x%lx\n", __FUNCTION__, rpmhdrClass); #ifdef NOTYET rb_include_module(rpmhdrClass, rb_mEnumerable); #endif rb_define_singleton_method(rpmhdrClass, "new", rpmhdr_new, -1); initProperties(rpmhdrClass); initMethods(rpmhdrClass); }
void Init_mixology() { VALUE Mixology = rb_define_module("Mixology"); rb_define_method(Mixology, "mixin", rb_mixin, 1); rb_define_method(Mixology, "unmix", rb_unmix, 1); /* Adding a hook to Module */ rb_define_method(rb_const_get(rb_cObject, rb_intern("Module")), "mixed_in", rb_mixed_in, 1); rb_define_method(rb_const_get(rb_cObject, rb_intern("Module")), "unmixed", rb_unmixed, 1); rb_include_module(rb_cObject, Mixology); }
void Init_rugged_submodule_collection(void) { rb_cRuggedSubmoduleCollection = rb_define_class_under(rb_mRugged, "SubmoduleCollection", rb_cObject); rb_include_module(rb_cRuggedSubmoduleCollection, rb_mEnumerable); rb_define_method(rb_cRuggedSubmoduleCollection, "initialize", rb_git_submodule_collection_initialize, 1); rb_define_method(rb_cRuggedSubmoduleCollection, "[]", rb_git_submodule_collection_aref, 1); rb_define_method(rb_cRuggedSubmoduleCollection, "each", rb_git_submodule_collection_each, 0); rb_define_method(rb_cRuggedSubmoduleCollection, "update", rb_git_submodule_update, 2); rb_define_method(rb_cRuggedSubmoduleCollection, "setup_add", rb_git_submodule_setup_add, -1); }