From 5b014a7427ef87fecb54c368cf3fe1efabb03f03 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 21 Oct 2005 09:00:02 +0000 Subject: * bin/erb (ERB::Main::run): typo fixed. [ruby-core:06337] * env.h: move struct METHOD and struct BLOCK from eval.c to support NodeWrap and ParseTree. * rubysig.h (CHECK_INTS): prevent signal handler to run during critical section. [ruby-core:04039] * eval.c (load_wait): need not to call rb_thread_schedule() explicitly. [ruby-core:04039] * eval.c (rb_thread_schedule): clear rb_thread_critical. [ruby-core:04039] * eval.c (rb_obj_instance_exec): create instance_exec and module_exec which pass arguments to the block. * eval.c (rb_f_funcall): rename fcall to funcall to follow tradition. * st.c (st_free_table): do not call free() but xfree(). [ruby-core:06205] * eval.c (splat_value): call rb_Array() to convert svalue to values. [ruby-dev:27397] * lib/cgi.rb (CGI::Cookie::parse): Cookies from Nokia devices may not be parsed correctly. A patch from August Z. Flatby (augustzf) in [ruby-Patches-2595]. [ruby-core:06183] * object.c (rb_Array): Array() to raise error for objects without to_ary, nor to_a. * object.c (nil_to_a): revert NilClass#to_a. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 694fcf3159..9f39ec3117 100644 --- a/object.c +++ b/object.c @@ -727,6 +727,22 @@ nil_to_s(VALUE obj) return rb_str_new2(""); } +/* + * call-seq: + * nil.to_a => [] + * + * Always returns an empty array. + * + * nil.to_a #=> [] + */ + +static VALUE +nil_to_a(obj) + VALUE obj; +{ + return rb_ary_new2(0); +} + /* * call-seq: * nil.inspect => "nil" @@ -2236,10 +2252,7 @@ rb_Array(VALUE val) VALUE tmp = rb_check_array_type(val); if (NIL_P(tmp)) { - tmp = rb_check_convert_type(val, T_ARRAY, "Array", "to_a"); - if (NIL_P(tmp)) { - return rb_ary_new3(1, val); - } + return rb_convert_type(val, T_ARRAY, "Array", "to_a"); } return tmp; } @@ -2250,8 +2263,6 @@ rb_Array(VALUE val) * * Returns arg as an Array. First tries to call * arg.to_ary, then arg.to_a. - * If both fail, creates a single element array containing arg - * (unless arg is nil). * * Array(1..5) #=> [1, 2, 3, 4, 5] */ @@ -2433,6 +2444,7 @@ Init_Object(void) rb_define_method(rb_cNilClass, "to_i", nil_to_i, 0); rb_define_method(rb_cNilClass, "to_f", nil_to_f, 0); rb_define_method(rb_cNilClass, "to_s", nil_to_s, 0); + rb_define_method(rb_cNilClass, "to_a", nil_to_a, 0); rb_define_method(rb_cNilClass, "inspect", nil_inspect, 0); rb_define_method(rb_cNilClass, "&", false_and, 1); rb_define_method(rb_cNilClass, "|", false_or, 1); -- cgit v1.2.3