* 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
Родитель d551b78d4a
Коммит a28d1eff65
4 изменённых файлов: 39 добавлений и 3 удалений

Просмотреть файл

@ -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.

6
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.

6
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);
}
/*

Просмотреть файл

@ -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)