ruby-changes:30472
From: usa <ko1@a...>
Date: Wed, 14 Aug 2013 14:35:30 +0900 (JST)
Subject: [ruby-changes:30472] usa:r42551 (trunk): * proc.c (rb_mod_define_method): now they return the symbols of the
usa 2013-08-14 14:35:21 +0900 (Wed, 14 Aug 2013) New Revision: 42551 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42551 Log: * proc.c (rb_mod_define_method): now they return the symbols of the defined methods, not the methods/procs themselves. [ruby-dev:42151] [Feature #3753] * NEWS: documents about above change and def-expr (see r42337). * test/ruby/test_module.rb: tests about above change. Modified files: trunk/ChangeLog trunk/NEWS trunk/proc.c trunk/test/ruby/test_module.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42550) +++ ChangeLog (revision 42551) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Aug 14 14:28:39 2013 NAKAMURA Usaku <usa@r...> + + * proc.c (rb_mod_define_method): now they return the symbols of the + defined methods, not the methods/procs themselves. + [ruby-dev:42151] [Feature #3753] + + * NEWS: documents about above change and def-expr (see r42337). + + * test/ruby/test_module.rb: tests about above change. + Wed Aug 14 00:51:14 2013 Tanaka Akira <akr@f...> * bignum.c (bigdivrem_restoring): xn argument removed. Index: proc.c =================================================================== --- proc.c (revision 42550) +++ proc.c (revision 42551) @@ -1569,8 +1569,8 @@ rb_mod_public_instance_method(VALUE mod, https://github.com/ruby/ruby/blob/trunk/proc.c#L1569 /* * call-seq: - * define_method(symbol, method) -> new_method - * define_method(symbol) { block } -> proc + * define_method(symbol, method) -> symbol + * define_method(symbol) { block } -> symbol * * Defines an instance method in the receiver. The _method_ * parameter can be a +Proc+, a +Method+ or an +UnboundMethod+ object. @@ -1667,7 +1667,7 @@ rb_mod_define_method(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/proc.c#L1667 rb_raise(rb_eTypeError, "wrong argument type (expected Proc/Method)"); } - return body; + return ID2SYM(id); } /* Index: NEWS =================================================================== --- NEWS (revision 42550) +++ NEWS (revision 42551) @@ -22,6 +22,8 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L22 * "42ri" and "3.14ri" are evaluated as Complex(0, 42r) and Complex(0, 3.14r), respectively. +* def-expr now returns the symbol of its name instead of nil. + === Core classes updates (outstanding ones only) * Binding @@ -101,6 +103,10 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L103 * The ancestors of a singleton class now include singleton classes, in particular itself. +* Module#define_method and Object#define_singleton_method + * Now they return the symbols of the defined methods, not the methods/procs + themselves. + * Numeric#quo * Raises TypeError instead of ArgumentError if the receiver doesn't have to_r method. Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 42550) +++ test/ruby/test_module.rb (revision 42551) @@ -1749,6 +1749,26 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1749 RUBY end + def test_return_value_of_define_method + retvals = [] + Class.new.class_eval do + retvals << define_method(:foo){} + retvals << define_method(:bar, instance_method(:foo)) + end + assert_equal :foo, retvals[0] + assert_equal :bar, retvals[1] + end + + def test_return_value_of_define_singleton_method + retvals = [] + Class.new do + retvals << define_singleton_method(:foo){} + retvals << define_singleton_method(:bar, method(:foo)) + end + assert_equal :foo, retvals[0] + assert_equal :bar, retvals[1] + end + private def assert_top_method_is_private(method) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/