mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* proc.c (rb_mod_define_method): should check Symbol or not.
[Bug #11850] * test/ruby/test_method.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3b8730058e
commit
a8b0c25293
3 changed files with 27 additions and 1 deletions
|
@ -1,3 +1,10 @@
|
|||
Sun Dec 20 11:14:11 2015 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* proc.c (rb_mod_define_method): should check Symbol or not.
|
||||
[Bug #11850]
|
||||
|
||||
* test/ruby/test_method.rb: add a test.
|
||||
|
||||
Sun Dec 20 11:01:57 2015 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* proc.c (rb_mod_define_method): fix notation.
|
||||
|
|
7
proc.c
7
proc.c
|
@ -1774,8 +1774,13 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
|
|||
rb_thread_t *th = GET_THREAD();
|
||||
rb_block_t *block = rb_vm_control_frame_block_ptr(th->cfp);
|
||||
if (!block) rb_raise(rb_eArgError, proc_without_block);
|
||||
|
||||
body = block->proc;
|
||||
if (!body) {
|
||||
|
||||
if (SYMBOL_P(body)) {
|
||||
body = rb_sym_to_proc(body);
|
||||
}
|
||||
else if (!body) {
|
||||
body = rb_vm_make_proc_lambda(th, block, rb_cProc, TRUE);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -939,4 +939,18 @@ class TestMethod < Test::Unit::TestCase
|
|||
assert_equal([:m1, :m2, :m3].sort, MethodInMethodClass.public_instance_methods(false).sort)
|
||||
assert_equal([].sort, MethodInMethodClass.private_instance_methods(false).sort)
|
||||
end
|
||||
|
||||
def test_define_method_with_symbol
|
||||
assert_normal_exit %q{
|
||||
define_method(:foo, &:to_s)
|
||||
define_method(:bar, :to_s.to_proc)
|
||||
}, '[Bug #11850]'
|
||||
c = Class.new{
|
||||
define_method(:foo, &:to_s)
|
||||
define_method(:bar, :to_s.to_proc)
|
||||
}
|
||||
obj = c.new
|
||||
assert_equal('1', obj.foo(1))
|
||||
assert_equal('1', obj.bar(1))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue