aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_module.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_module.rb')
-rw-r--r--test/ruby/test_module.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 8084fdab45..9d6e13d676 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -2011,6 +2011,25 @@ class TestModule < Test::Unit::TestCase
RUBY
end
+ def test_define_method_with_unbound_method
+ # Passing an UnboundMethod to define_method succeeds if it is from an ancestor
+ assert_nothing_raised do
+ cls = Class.new(String) do
+ define_method('foo', String.instance_method(:to_s))
+ end
+
+ obj = cls.new('bar')
+ assert_equal('bar', obj.foo)
+ end
+
+ # Passing an UnboundMethod to define_method fails if it is not from an ancestor
+ assert_raise(TypeError) do
+ Class.new do
+ define_method('foo', String.instance_method(:to_s))
+ end
+ end
+ end
+
private
def assert_top_method_is_private(method)