diff options
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | array.c | 14 | ||||
-rw-r--r-- | eval.c | 7 | ||||
-rw-r--r-- | object.c | 26 | ||||
-rw-r--r-- | string.c | 5 |
5 files changed, 70 insertions, 3 deletions
@@ -1,3 +1,11 @@ +Mon Feb 10 10:14:26 2003 Yukihiro Matsumoto <matz@ruby-lang.org> + + * 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. + Mon Feb 10 03:33:42 2003 WATANABE Hirofumi <eban@ruby-lang.org> * io.c (rb_file_sysopen): rb_file_sysopen_internal() needs four @@ -54,6 +62,19 @@ Sat Feb 8 03:34:28 2003 Akinori MUSHA <knu@iDaemons.org> * ruby.h (NORETURN_STYLE_NEW): Ditto. +Sat Feb 8 00:47:24 2003 Yukihiro Matsumoto <matz@ruby-lang.org> + + * 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] + Fri Feb 7 15:35:21 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net> * intern.h, re.c (rb_memsearch): returns long. @@ -1001,6 +1001,18 @@ static VALUE rb_ary_to_a(ary) VALUE ary; { + if (rb_obj_class(ary) != rb_cArray) { + VALUE dup = rb_ary_new2(RARRAY(ary)->len); + rb_ary_replace(dup, ary); + return dup; + } + return ary; +} + +static VALUE +rb_ary_to_ary_m(ary) + VALUE ary; +{ return ary; } @@ -1891,7 +1903,7 @@ Init_Array() rb_define_method(rb_cArray, "to_s", rb_ary_to_s, 0); rb_define_method(rb_cArray, "inspect", rb_ary_inspect, 0); rb_define_method(rb_cArray, "to_a", rb_ary_to_a, 0); - rb_define_method(rb_cArray, "to_ary", rb_ary_to_a, 0); + rb_define_method(rb_cArray, "to_ary", rb_ary_to_ary_m, 0); rb_define_method(rb_cArray, "frozen?", rb_ary_frozen_p, 0); rb_define_method(rb_cArray, "==", rb_ary_equal, 1); @@ -4352,6 +4352,7 @@ static int last_call_status; #define CSTAT_PRIV 1 #define CSTAT_PROT 2 #define CSTAT_VCALL 4 +#define CSTAT_SUPER 8 static VALUE rb_f_missing(argc, argv, obj) @@ -4412,6 +4413,9 @@ rb_f_missing(argc, argv, obj) exc = rb_eNameError; } } + else if (last_call_status & CSTAT_SUPER) { + format = "super: no superclass method `%s'"; + } if (!format) { format = "undefined method `%s' for %s%s%s"; } @@ -4807,8 +4811,7 @@ rb_call(klass, recv, mid, argc, argv, scope) } else if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) { if (scope == 3) { - rb_name_error(mid, "super: no superclass method `%s'", - rb_id2name(mid)); + return rb_undefined(recv, mid, argc, argv, CSTAT_SUPER); } return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0); } @@ -926,6 +926,30 @@ rb_obj_public_methods(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; const char *tname, *method; @@ -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); @@ -1849,6 +1849,11 @@ static VALUE rb_str_to_s(str) VALUE str; { + if (rb_obj_class(str) != rb_cString) { + VALUE dup = str_alloc(rb_cString); + rb_str_replace(dup, str); + return dup; + } return str; } |