From ab24be4e98660f4fbef44a03262f25988a260b9f Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 10 Feb 2003 09:40:13 +0000 Subject: * array.c (rb_ary_to_a): return value should be an Array if the receiver is an instance of subclass of Array. * string.c (rb_str_to_s): return value should be a String if the receiver is an instance of subclass of String. * eval.c (rb_call): calls method_missing when superclass method does not exist. * eval.c (rb_f_missing): now handles "no super" case. * object.c (rb_obj_ivar_get): Object#instance_variable_get: new method to get instance variable value without eval(). [new] * object.c (rb_obj_ivar_set): Object#instance_variable_set: new method to set instance variable value without eval(). [new] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'object.c') diff --git a/object.c b/object.c index 7a59abee13..5cfc3ed579 100644 --- a/object.c +++ b/object.c @@ -925,6 +925,30 @@ rb_obj_public_methods(obj) return rb_class_public_instance_methods(1, argv, CLASS_OF(obj)); } +static VALUE +rb_obj_ivar_get(obj, iv) + VALUE obj, iv; +{ + ID id = rb_to_id(iv); + + if (!rb_is_instance_id(id)) { + rb_name_error(id, "`%s' is not an instance variable name", rb_id2name(id)); + } + return rb_ivar_get(obj, id); +} + +static VALUE +rb_obj_ivar_set(obj, iv, val) + VALUE obj, iv, val; +{ + ID id = rb_to_id(iv); + + if (!rb_is_instance_id(id)) { + rb_name_error(id, "`%s' is not an instance variable name", rb_id2name(id)); + } + return rb_ivar_set(obj, id, val); +} + static VALUE convert_type(val, tname, method, raise) VALUE val; @@ -1346,6 +1370,8 @@ Init_Object() rb_define_method(rb_mKernel, "private_methods", rb_obj_private_methods, 0); rb_define_method(rb_mKernel, "public_methods", rb_obj_public_methods, 0); rb_define_method(rb_mKernel, "instance_variables", rb_obj_instance_variables, 0); + rb_define_method(rb_mKernel, "instance_variable_get", rb_obj_ivar_get, 1); + rb_define_method(rb_mKernel, "instance_variable_set", rb_obj_ivar_set, 2); rb_define_private_method(rb_mKernel, "remove_instance_variable", rb_obj_remove_instance_variable, 1); -- cgit v1.2.3