diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-31 08:18:09 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-31 08:18:09 +0000 |
commit | c68234f7d1fa9f2e9a1874b547f1f3e48eff5ae1 (patch) | |
tree | f802df08e85bf05cf0d0511e9f3277a697c0ff3e /test/ruby/test_method.rb | |
parent | 651c561b488ac97eed507a431a51c32214234597 (diff) | |
download | ruby-c68234f7d1fa9f2e9a1874b547f1f3e48eff5ae1.tar.gz |
proc.c: consider noex in define_method
* proc.c (rb_mod_define_method): consider visibility in define_method.
patch by mashiro <mail AT mashiro.org>. fix GH-268.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_method.rb')
-rw-r--r-- | test/ruby/test_method.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index c1dbd9f35f..655fac5d3b 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -270,6 +270,38 @@ class TestMethod < Test::Unit::TestCase assert_equal(:meth, c.new.meth, feature4254) end + def test_define_method_visibility + c = Class.new do + public + define_method(:foo) {:foo} + protected + define_method(:bar) {:bar} + private + define_method(:baz) {:baz} + end + + assert_equal(true, c.public_method_defined?(:foo)) + assert_equal(false, c.public_method_defined?(:bar)) + assert_equal(false, c.public_method_defined?(:baz)) + + assert_equal(false, c.protected_method_defined?(:foo)) + assert_equal(true, c.protected_method_defined?(:bar)) + assert_equal(false, c.protected_method_defined?(:baz)) + + assert_equal(false, c.private_method_defined?(:foo)) + assert_equal(false, c.private_method_defined?(:bar)) + assert_equal(true, c.private_method_defined?(:baz)) + + m = Module.new do + module_function + define_method(:foo) {:foo} + end + assert_equal(true, m.respond_to?(:foo)) + assert_equal(false, m.public_method_defined?(:foo)) + assert_equal(false, m.protected_method_defined?(:foo)) + assert_equal(true, m.private_method_defined?(:foo)) + end + def test_super_in_proc_from_define_method c1 = Class.new { def m |