/* Module initializer */ void rb_init_apache_multival() { VALUE dmethods; VALUE args[1]; /* Kluge to make Rdoc see the associations in this file */ #if FOR_RDOC_PARSER rb_mApache = rb_define_module( "Apache" ); #endif rb_cApacheMultiVal = rb_define_class_under( rb_mApache, "MultiVal", rb_cObject ); /* Define IDs which indicate to the delegator-creator whether it's supposed to delegate to the whole array or just the first element. */ stringish = rb_intern("stringish"); arrayish = rb_intern("arrayish"); /* Since rb_load_path isn't yet set up, we have to set up our own delegation instead of relying on 'forwardable'. Set up stringish delegation first. */ args[0] = Qfalse; dmethods = rb_class_instance_methods( 1, args, rb_cString ); rb_ary_delete( dmethods, rb_str_new2("each") ); rb_ary_delete( dmethods, rb_str_new2("[]") ); rb_ary_delete( dmethods, rb_str_new2("[]=") ); /* TODO: avoid SEGV */ #if 0 rb_iterate( rb_each, dmethods, multival_make_delegator, stringish ); /* Now set up array-ish delegation */ dmethods = rb_class_instance_methods( 1, args, rb_cArray ); rb_iterate( rb_each, dmethods, multival_make_delegator, arrayish ); #endif /* include Comparable */ rb_include_module( rb_cApacheMultiVal, rb_mComparable ); /* Instance methods */ rb_define_method( rb_cApacheMultiVal, "initialize", multival_init, -2 ); rb_define_method( rb_cApacheMultiVal, "to_s", multival_to_s, 0 ); rb_define_method( rb_cApacheMultiVal, "to_str", multival_to_s, 0 ); rb_define_alias ( rb_cApacheMultiVal, "as_string", "to_s" ); rb_define_method( rb_cApacheMultiVal, "to_a", multival_to_a, 0 ); rb_define_method( rb_cApacheMultiVal, "to_ary", multival_to_a, 0 ); rb_define_alias ( rb_cApacheMultiVal, "as_array", "to_a" ); rb_define_method( rb_cApacheMultiVal, "<=>", multival_compare, 1 ); }
SEXP R_rb_class_instance_methods(SEXP r_obj, SEXP r_convert, SEXP super) { SEXP r_ans; VALUE args[1]; VALUE obj, ans; args[0] = LOGICAL(super)[0] ? Qtrue : Qfalse ; obj = getRubyObjectFromR(r_obj); if(TYPE(obj) == RUBY_T_OBJECT) obj = CLASS_OF(obj); obj = rb_cString; ans = rb_class_instance_methods(1, args, obj); return(convertRubyToR(ans, r_convert)); }