Functions

Defining methods

There are some APIs to define a method from C. More...

Functions

void rb_define_method_id (VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc)
void rb_define_method (VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void rb_define_protected_method (VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void rb_define_private_method (VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void rb_undef_method (VALUE klass, const char *name)
void rb_define_singleton_method (VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
 Defines a singleton method for obj.
void rb_define_module_function (VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
 Defines a module function for module.
void rb_define_global_function (const char *name, VALUE(*func)(ANYARGS), int argc)
 Defines a global function.
void rb_define_alias (VALUE klass, const char *name1, const char *name2)
 Defines an alias of a method.
void rb_define_attr (VALUE klass, const char *name, int read, int write)
 Defines (a) public accessor method(s) for an attribute.
int rb_obj_basic_to_s_p (VALUE obj)
int rb_scan_args (int argc, const VALUE *argv, const char *fmt,...)

Detailed Description

There are some APIs to define a method from C.

These API takes a C function as a method body.

Method body functions
Method body functions must return a VALUE and can be one of the following form:
Fixed number of parameters

This form is a normal C function, excepting it takes a receiver object as the first argument.

     static VALUE my_method(VALUE self, VALUE x, VALUE y);
argc and argv style

This form takes three parameters: argc, argv and self. self is the receiver. argc is the number of arguments. argv is a pointer to an array of the arguments.

     static VALUE my_method(int argc, VALUE *argv, VALUE self);
Ruby array style

This form takes two parameters: self and args. self is the receiver. args is an Array object which contains the arguments.

     static VALUE my_method(VALUE self, VALUE args);

Number of parameters
Method defining APIs takes the number of parameters which the method will takes. This number is called argc. argc can be:
zero or positive number
This means the method body function takes a fixed number of parameters
-1
This means the method body function is "argc and argv" style.
-2
This means the method body function is "self and args" style.

Function Documentation

void rb_define_alias ( VALUE  klass,
const char *  name1,
const char *  name2 
)

Defines an alias of a method.

Parameters:
klass the class which the original method belongs to
name1 a new name for the method
name2 the original name of the method

Definition at line 1346 of file class.c.

References rb_alias(), and rb_intern.

Referenced by Init_Array(), Init_Hash(), Init_IO(), Init_nkf(), Init_ossl_asn1(), Init_ossl_config(), Init_ossl_dh(), Init_ossl_digest(), Init_ossl_dsa(), Init_ossl_hmac(), Init_ossl_ns_spki(), Init_ossl_pkcs7(), Init_ossl_rsa(), Init_ossl_ssl(), Init_ossl_x509cert(), Init_ossl_x509crl(), Init_ossl_x509name(), Init_ossl_x509req(), Init_process(), Init_Struct(), and Init_win32ole().

void rb_define_attr ( VALUE  klass,
const char *  name,
int  read,
int  write 
)

Defines (a) public accessor method(s) for an attribute.

Parameters:
klass the class which the attribute will belongs to
name name of the attribute
read a getter method for the attribute will be defined if read is non-zero.
write a setter method for the attribute will be defined if write is non-zero.

Definition at line 1359 of file class.c.

References FALSE, rb_attr(), and rb_intern.

Referenced by Init_syck().

void rb_define_global_function ( const char *  name,
VALUE(*)(ANYARGS)  func,
int  argc 
)

Defines a global function.

Parameters:
name name of the function
func the method body
argc the number of parameters, or -1 or -2. see Defining methods.

Definition at line 1333 of file class.c.

References func, rb_define_module_function(), and rb_mKernel.

Referenced by Init_bigdecimal(), Init_Binding(), Init_Complex(), Init_eval(), Init_Exception(), Init_File(), Init_IO(), Init_jump(), Init_load(), Init_Object(), Init_Proc(), Init_process(), Init_Random(), Init_Rational(), Init_signal(), Init_Thread(), Init_vm_eval(), process_options(), and ruby_Init_Continuation_body().

void rb_define_method ( VALUE  klass,
const char *  name,
VALUE(*)(ANYARGS)  func,
int  argc 
)

Definition at line 1171 of file class.c.

References func, NOEX_PUBLIC, rb_add_method_cfunc(), and rb_intern.

Referenced by Init_Array(), Init_bigdecimal(), Init_Bignum(), Init_Binding(), Init_bubblebabble(), Init_Comparable(), Init_Complex(), Init_Cont(), Init_cstr(), Init_curses(), Init_dbm(), Init_digest(), Init_Dir(), Init_dlcfunc(), Init_dlhandle(), Init_dlptr(), Init_Encoding(), Init_Enumerable(), Init_Enumerator(), Init_eval(), Init_eval_method(), Init_Exception(), Init_fiddle_closure(), Init_fiddle_function(), Init_File(), Init_GC(), Init_gdbm(), Init_generator(), Init_Hash(), Init_iconv(), Init_IO(), Init_ISeq(), Init_load(), Init_nonblock(), Init_Numeric(), Init_Object(), Init_ossl_asn1(), Init_ossl_cipher(), Init_ossl_config(), Init_ossl_dh(), Init_ossl_digest(), Init_ossl_dsa(), Init_ossl_hmac(), Init_ossl_ns_spki(), Init_ossl_pkcs12(), Init_ossl_pkcs7(), Init_ossl_pkey(), Init_ossl_rsa(), Init_ossl_ssl(), Init_ossl_ssl_session(), Init_ossl_x509attr(), Init_ossl_x509cert(), Init_ossl_x509crl(), Init_ossl_x509ext(), Init_ossl_x509name(), Init_ossl_x509req(), Init_ossl_x509revoked(), Init_ossl_x509store(), Init_pack(), Init_parser(), Init_Proc(), Init_process(), Init_psych_emitter(), Init_psych_parser(), Init_pty(), Init_Random(), Init_Range(), Init_Rational(), Init_Regexp(), Init_sdbm(), Init_set_len(), Init_signal(), Init_socket(), Init_String(), Init_string(), Init_stringio(), Init_strscan(), Init_Struct(), Init_syck(), Init_tcltklib(), Init_Thread(), Init_Time(), Init_tkutil(), Init_transcode(), Init_vm_eval(), Init_wait(), Init_win32ole(), Init_zlib(), rb_define_singleton_method(), rsock_init_addrinfo(), rsock_init_ancdata(), rsock_init_basicsocket(), rsock_init_ipsocket(), rsock_init_sockopt(), rsock_init_sockssocket(), rsock_init_tcpserver(), rsock_init_tcpsocket(), rsock_init_udpsocket(), rsock_init_unixserver(), rsock_init_unixsocket(), ruby_Init_Continuation_body(), and ruby_Init_Fiber_as_Coroutine().

void rb_define_method_id ( VALUE  klass,
ID  mid,
VALUE(*)(ANYARGS)  func,
int  argc 
)

Definition at line 1165 of file class.c.

References func, NOEX_PUBLIC, and rb_add_method_cfunc().

Referenced by Init_VM(), and make_struct().

void rb_define_module_function ( VALUE  module,
const char *  name,
VALUE(*)(ANYARGS)  func,
int  argc 
)
void rb_define_private_method ( VALUE  klass,
const char *  name,
VALUE(*)(ANYARGS)  func,
int  argc 
)
void rb_define_protected_method ( VALUE  klass,
const char *  name,
VALUE(*)(ANYARGS)  func,
int  argc 
)

Definition at line 1177 of file class.c.

References func, NOEX_PROTECTED, rb_add_method_cfunc(), and rb_intern.

void rb_define_singleton_method ( VALUE  obj,
const char *  name,
VALUE(*)(ANYARGS)  func,
int  argc 
)
int rb_obj_basic_to_s_p ( VALUE  obj  ) 
int rb_scan_args ( int  argc,
const VALUE argv,
const char *  fmt,
  ... 
)

Definition at line 1377 of file class.c.

References ISDIGIT, rb_ary_new(), rb_ary_new4(), rb_block_given_p(), rb_block_proc(), rb_eArgError, rb_fatal(), and rb_raise().

Referenced by addrinfo_getnameinfo(), addrinfo_initialize(), addrinfo_s_getaddrinfo(), argf_read(), argf_readpartial(), ary_take_first_or_last(), BigDecimal_ceil(), BigDecimal_div2(), BigDecimal_dump(), BigDecimal_floor(), BigDecimal_global_new(), BigDecimal_limit(), BigDecimal_mode(), BigDecimal_new(), BigDecimal_round(), BigDecimal_to_s(), BigDecimal_truncate(), bind_eval(), bsock_setsockopt(), bsock_shutdown(), cbsubst_table_setup(), class_instance_method_list(), count_nodes(), count_objects(), count_objects_size(), count_tdata_objects(), cParser_initialize(), cState_initialize(), define_final(), dir_initialize(), dir_s_chdir(), dir_s_glob(), dir_s_home(), dir_s_mkdir(), do_checksum(), econv_args(), econv_primitive_convert(), econv_putback(), enc_dump(), enum_chunk(), enum_count(), enum_cycle(), enum_find(), enum_find_index(), enum_first(), enum_inject(), enum_slice_before(), enumerator_with_index(), env_fetch(), etc_getgrgid(), etc_getpwuid(), ev_advise(), ev_on_event(), exc_initialize(), f_round_common(), fdbm_fetch_m(), fdbm_initialize(), fev_off_event(), fgdbm_fetch_m(), fgdbm_initialize(), file_s_fnmatch(), fix_to_s(), flo_round(), float_rationalize(), fole_initialize(), fole_s_connect(), fole_s_const_load(), fole_s_show_help(), fsdbm_fetch_m(), fsdbm_initialize(), gc_profile_report(), generator_initialize(), iconv_iconv(), iconv_initialize(), iconv_s_open(), initialize(), int_round(), integer_rationalize(), interrupt_init(), io_getpartial(), io_read(), io_wait(), ip_cancel_eval(), ip_cancel_eval_unwind(), ip_create_slave(), ip_fromUTF8(), ip_init(), ip_toUTF8(), iseq_s_compile(), iseq_s_compile_file(), iseq_s_load(), lib_do_one_event_core(), lib_fromUTF8(), lib_mainloop(), lib_mainloop_watchdog(), lib_thread_callback(), lib_toUTF8(), mArray_to_json(), marshal_dump(), marshal_load(), match_aref(), math_log(), mFalseClass_to_json(), mFloat_to_json(), mHash_to_json(), mInteger_to_json(), mNilClass_to_json(), mObject_to_json(), mString_to_json(), mSyslog_open(), mTrueClass_to_json(), mutex_sleep(), nilclass_rationalize(), nucomp_rationalize(), nucomp_s_convert(), nucomp_s_new(), nucomp_s_polar(), nurat_rationalize(), nurat_s_convert(), nurat_s_new(), obj_respond_to(), ole_create_dcom(), ole_invoke(), os_each_obj(), ossl_asn1_initialize(), ossl_bn_initialize(), ossl_bn_to_s(), ossl_cipher_init(), ossl_cipher_pkcs5_keyivgen(), ossl_cipher_update(), ossl_config_get_value_old(), ossl_config_initialize(), ossl_dh_initialize(), ossl_dh_s_generate(), ossl_digest_finish(), ossl_digest_initialize(), ossl_dsa_export(), ossl_dsa_initialize(), ossl_pkcs12_initialize(), ossl_pkcs12_s_create(), ossl_pkcs7_decrypt(), ossl_pkcs7_initialize(), ossl_pkcs7_s_encrypt(), ossl_pkcs7_s_sign(), ossl_pkcs7_s_write_smime(), ossl_pkcs7_verify(), ossl_rsa_export(), ossl_rsa_initialize(), ossl_rsa_private_decrypt(), ossl_rsa_private_encrypt(), ossl_rsa_public_decrypt(), ossl_rsa_public_encrypt(), ossl_rsa_s_generate(), ossl_spki_initialize(), ossl_ssl_initialize(), ossl_ssl_read_internal(), ossl_sslctx_flush_sessions(), ossl_sslctx_initialize(), ossl_x509_initialize(), ossl_x509attr_initialize(), ossl_x509crl_initialize(), ossl_x509ext_initialize(), ossl_x509extfactory_create_ext(), ossl_x509extfactory_initialize(), ossl_x509name_add_entry(), ossl_x509name_initialize(), ossl_x509name_to_s(), ossl_x509req_initialize(), ossl_x509stctx_initialize(), ossl_x509store_verify(), prepare_getline_args(), proc_curry(), proc_wait(), pty_check(), random_init(), range_first(), range_initialize(), range_step(), rb_ary_aref(), rb_ary_count(), rb_ary_cycle(), rb_ary_fetch(), rb_ary_fill(), rb_ary_flatten(), rb_ary_flatten_bang(), rb_ary_index(), rb_ary_initialize(), rb_ary_join_m(), rb_ary_permutation(), rb_ary_rindex(), rb_ary_rotate_bang(), rb_ary_rotate_m(), rb_ary_sample(), rb_ary_slice_bang(), rb_big_to_s(), rb_class_initialize(), rb_deflate_deflate(), rb_deflate_flush(), rb_deflate_initialize(), rb_deflate_s_deflate(), rb_digest_instance_digest(), rb_digest_instance_hexdigest(), rb_dlcfunc_initialize(), rb_dlhandle_initialize(), rb_dlptr_aref(), rb_dlptr_aset(), rb_dlptr_initialize(), rb_dlptr_s_malloc(), rb_dlptr_to_s(), rb_dlptr_to_str(), rb_f_abort(), rb_f_caller(), rb_f_catch(), rb_f_eval(), rb_f_exit(), rb_f_exit_bang(), rb_f_integer(), rb_f_load(), rb_f_rand(), rb_f_select(), rb_f_srand(), rb_f_throw(), rb_f_trace_var(), rb_f_untrace_var(), rb_file_s_absolute_path(), rb_file_s_basename(), rb_file_s_chmod(), rb_file_s_chown(), rb_file_s_expand_path(), rb_file_s_realdirpath(), rb_file_s_realpath(), rb_file_s_utime(), rb_hash_default(), rb_hash_fetch_m(), rb_hash_initialize(), rb_inflate_initialize(), rb_io_initialize(), rb_io_ioctl(), rb_io_reopen(), rb_io_s_binread(), rb_io_s_copy_stream(), rb_io_s_foreach(), rb_io_s_pipe(), rb_io_s_popen(), rb_io_s_read(), rb_io_s_readlines(), rb_io_s_sysopen(), rb_io_seek_m(), rb_io_set_encoding(), rb_io_sysread(), rb_io_sysseek(), rb_mod_const_defined(), rb_mod_const_get(), rb_mod_constants(), rb_obj_display(), rb_obj_methods(), rb_obj_singleton_methods(), rb_reg_match_m(), rb_reg_s_last_match(), rb_scan_open_args(), rb_str_chomp_bang(), rb_str_each_line(), rb_str_index_m(), rb_str_init(), rb_str_justify(), rb_str_rindex_m(), rb_str_split_m(), rb_str_sum(), rb_str_to_i(), rb_str_upto(), rb_struct_s_def(), readline_readline(), rsock_bsock_send(), rsock_s_recvfrom(), rsock_s_recvfrom_nonblock(), sock_initialize(), sock_s_getaddrinfo(), sock_s_gethostbyaddr(), sock_s_getnameinfo(), sock_s_getservbyname(), sock_s_getservbyport(), strio_getline(), strio_init(), strio_seek(), strscan_initialize(), syck_emitter_emit(), syck_emitter_reset(), syck_out_map(), syck_out_scalar(), syck_out_seq(), syck_parser_initialize(), syck_parser_load(), syck_parser_load_documents(), syserr_initialize(), tcp_init(), tcp_svr_init(), thread_join_m(), time_arg(), time_dump(), time_getlocaltime(), time_init_1(), time_localtime_m(), time_round(), time_s_at(), tk_do_callback(), tk_eval_cmd(), tk_get_eval_string(), tk_install_cmd(), udp_init(), udp_send(), and window_box().

void rb_undef_method ( VALUE  klass,
const char *  name 
)