1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
usa 2013-08-14 05:35:21 +00:00
parent d551b78d4a
commit a28d1eff65
4 changed files with 39 additions and 3 deletions

View file

@ -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> Wed Aug 14 00:51:14 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bigdivrem_restoring): xn argument removed. * bignum.c (bigdivrem_restoring): xn argument removed.

6
NEWS
View file

@ -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), * "42ri" and "3.14ri" are evaluated as Complex(0, 42r) and Complex(0, 3.14r),
respectively. respectively.
* def-expr now returns the symbol of its name instead of nil.
=== Core classes updates (outstanding ones only) === Core classes updates (outstanding ones only)
* Binding * Binding
@ -101,6 +103,10 @@ with all sufficient information, see the ChangeLog file.
* The ancestors of a singleton class now include singleton classes, * The ancestors of a singleton class now include singleton classes,
in particular itself. 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 * Numeric#quo
* Raises TypeError instead of ArgumentError if the receiver doesn't have * Raises TypeError instead of ArgumentError if the receiver doesn't have
to_r method. to_r method.

6
proc.c
View file

@ -1569,8 +1569,8 @@ rb_mod_public_instance_method(VALUE mod, VALUE vid)
/* /*
* call-seq: * call-seq:
* define_method(symbol, method) -> new_method * define_method(symbol, method) -> symbol
* define_method(symbol) { block } -> proc * define_method(symbol) { block } -> symbol
* *
* Defines an instance method in the receiver. The _method_ * Defines an instance method in the receiver. The _method_
* parameter can be a +Proc+, a +Method+ or an +UnboundMethod+ object. * 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)"); rb_raise(rb_eTypeError, "wrong argument type (expected Proc/Method)");
} }
return body; return ID2SYM(id);
} }
/* /*

View file

@ -1749,6 +1749,26 @@ class TestModule < Test::Unit::TestCase
RUBY RUBY
end 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 private
def assert_top_method_is_private(method) def assert_top_method_is_private(method)