From: Nobuyoshi Nakada Date: 2008-05-21T10:16:16+09:00 Subject: [ruby-dev:34780] Re: (1..5).step(SimpleDelegator.new(1.5)) {|x| p x} differ from (1..5).step(1.5) {|x| p x} なかだです。 At Wed, 21 May 2008 00:37:24 +0900, Tanaka Akira wrote in [ruby-dev:34775]: > 以下のように (1..5).step(1.5) {|x| p x} と > (1..5).step(SimpleDelegator.new(1.5)) {|x| p x} の結果が異な > るのは変ではないでしょうか。 やはり、Float#to_intは廃止することを主張します。 Index: numeric.c =================================================================== --- numeric.c (revision 16501) +++ numeric.c (working copy) @@ -454,18 +454,4 @@ num_nonzero_p(VALUE num) } -/* - * call-seq: - * num.to_int => integer - * - * Invokes the child class's to_i method to convert - * num to an integer. - */ - -static VALUE -num_to_int(VALUE num) -{ - return rb_funcall(num, id_to_i, 0, 0); -} - /******************************************************************** @@ -3116,5 +3102,4 @@ Init_Numeric(void) rb_define_method(rb_cNumeric, "remainder", num_remainder, 1); rb_define_method(rb_cNumeric, "abs", num_abs, 0); - rb_define_method(rb_cNumeric, "to_int", num_to_int, 0); rb_define_method(rb_cNumeric, "scalar?", num_scalar_p, 0); @@ -3247,5 +3232,4 @@ Init_Numeric(void) rb_define_method(rb_cFloat, "to_i", flo_truncate, 0); - rb_define_method(rb_cFloat, "to_int", flo_truncate, 0); rb_define_method(rb_cFloat, "floor", flo_floor, 0); rb_define_method(rb_cFloat, "ceil", flo_ceil, 0); Index: range.c =================================================================== --- range.c (revision 16501) +++ range.c (working copy) @@ -307,6 +307,7 @@ range_step(int argc, VALUE *argv, VALUE else { rb_scan_args(argc, argv, "01", &step); - if (!rb_obj_is_kind_of(step, rb_cNumeric)) { - step = rb_to_int(step); + tmp = rb_check_to_integer(step, "to_int"); + if (!NIL_P(tmp)) { + step = tmp; } if (rb_funcall(step, '<', 1, INT2FIX(0))) { Index: lib/delegate.rb =================================================================== --- lib/delegate.rb (revision 16501) +++ lib/delegate.rb (working copy) @@ -153,7 +153,7 @@ class Delegator # call through \_\_getobj\_\_. # - def respond_to?(m) + def respond_to?(m, *priv) return true if super - return self.__getobj__.respond_to?(m) + return self.__getobj__.respond_to?(m, *priv) end -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦