From a28d1eff6534328cae5363bbf0cc26cd0a18b948 Mon Sep 17 00:00:00 2001 From: usa Date: Wed, 14 Aug 2013 05:35:21 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ NEWS | 6 ++++++ proc.c | 6 +++--- test/ruby/test_module.rb | 20 ++++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9fd1251536..fbf727fe06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Wed Aug 14 14:28:39 2013 NAKAMURA Usaku + + * 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 * bignum.c (bigdivrem_restoring): xn argument removed. diff --git a/NEWS b/NEWS index a3b560962a..c823acf4b4 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ with all sufficient information, see the ChangeLog file. * "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 ChangeLog file. * 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. diff --git a/proc.c b/proc.c index 6fd3981ef6..e45d30bd8e 100644 --- a/proc.c +++ b/proc.c @@ -1569,8 +1569,8 @@ rb_mod_public_instance_method(VALUE mod, VALUE vid) /* * 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 *argv, VALUE mod) rb_raise(rb_eTypeError, "wrong argument type (expected Proc/Method)"); } - return body; + return ID2SYM(id); } /* diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index b0a33c8609..1124101664 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1749,6 +1749,26 @@ class TestModule < Test::Unit::TestCase 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)