diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-14 05:35:21 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-14 05:35:21 +0000 |
commit | a28d1eff6534328cae5363bbf0cc26cd0a18b948 (patch) | |
tree | 846b20ae8ec12c856eca10bcf108f00646e0fd16 | |
parent | d551b78d4ad27c1c9a4026d11896d4630a1ffed8 (diff) | |
download | ruby-a28d1eff6534328cae5363bbf0cc26cd0a18b948.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | proc.c | 6 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 20 |
4 files changed, 39 insertions, 3 deletions
@@ -1,3 +1,13 @@ +Wed Aug 14 14:28:39 2013 NAKAMURA Usaku <usa@ruby-lang.org> + + * 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@fsij.org> * bignum.c (bigdivrem_restoring): xn argument removed. @@ -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. @@ -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) |