static int pg_text_enc_in_ruby(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx) { int arity = rb_obj_method_arity(conv->coder_obj, s_id_encode); if( arity == 1 ){ VALUE out_str = rb_funcall( conv->coder_obj, s_id_encode, 1, value ); StringValue( out_str ); *intermediate = rb_str_export_to_enc(out_str, rb_enc_from_index(enc_idx)); }else{ VALUE enc = rb_enc_from_encoding(rb_enc_from_index(enc_idx)); VALUE out_str = rb_funcall( conv->coder_obj, s_id_encode, 2, value, enc ); StringValue( out_str ); *intermediate = out_str; } return -1; }
int rb_obj_respond_to(VALUE obj, ID id, int priv) { VALUE klass = CLASS_OF(obj); if (rb_method_basic_definition_p(klass, idRespond_to)) { return basic_obj_respond_to(obj, id, !priv); } else { int argc = 1; VALUE args[2]; args[0] = ID2SYM(id); args[1] = Qtrue; if (priv) { if (rb_obj_method_arity(obj, idRespond_to) != 1) { argc = 2; } else if (!NIL_P(ruby_verbose)) { VALUE klass = CLASS_OF(obj); VALUE location = rb_mod_method_location(klass, idRespond_to); rb_warn("%"PRIsVALUE"%c""respond_to?(:%"PRIsVALUE") is" " old fashion which takes only one parameter", (FL_TEST(klass, FL_SINGLETON) ? obj : klass), (FL_TEST(klass, FL_SINGLETON) ? '.' : '#'), QUOTE_ID(id)); if (!NIL_P(location)) { VALUE path = RARRAY_AREF(location, 0); VALUE line = RARRAY_AREF(location, 1); if (!NIL_P(path)) { rb_compile_warn(RSTRING_PTR(path), NUM2INT(line), "respond_to? is defined here"); } } } } return RTEST(rb_funcall2(obj, idRespond_to, argc, args)); } }
static VALUE obj_method_arity(VALUE self, VALUE obj, VALUE mid) { int arity = rb_obj_method_arity(obj, rb_check_id(&mid)); return INT2FIX(arity); }