From 0824f9f224117ce26973df3ebc6216d03723dd0e Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 13 May 2013 05:52:03 +0000 Subject: proc.c: Kernel#singleton_method * proc.c (rb_obj_singleton_method): new method Kernel#singleton_method which returns a Method object of the singleton method. non-singleton method causes NameError, but not aliased or zsuper method, right now. [ruby-core:54914] [Feature #8391] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_method.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 655fac5d3b..8fd7de823c 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -629,4 +629,16 @@ class TestMethod < Test::Unit::TestCase end assert_raise(Timeout::Error, bug8100) {raise e if e} end + + def test_singleton_method + feature8391 = '[ruby-core:54914] [Feature #8391]' + c1 = Class.new + c1.class_eval { def foo; :foo; end } + o = c1.new + def o.bar; :bar; end + assert_nothing_raised(NameError) {o.method(:foo)} + assert_raise(NameError, feature8391) {o.singleton_method(:foo)} + m = assert_nothing_raised(NameError, feature8391) {break o.singleton_method(:bar)} + assert_equal(:bar, m.call, feature8391) + end end -- cgit v1.2.3