mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
* 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
This commit is contained in:
parent
b53549941d
commit
ab24be4e98
5 changed files with 70 additions and 3 deletions
26
object.c
26
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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue