From c2a04d87d0f51e871e2fc0254ce6f90136b50169 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 23 Apr 2015 02:35:58 +0000 Subject: vm_eval.c: allow symbols to instance_eval/exec * vm_eval.c (rb_obj_instance_eval, rb_obj_instance_exec): allow symbols to just instance_eval/exec, execept for definition of singletons. [ruby-core:68961] [Bug #11086] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_symbol.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 66c62cb298..0a055db2c9 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -199,6 +199,35 @@ class TestSymbol < Test::Unit::TestCase assert_raise(TypeError) { a = :foo; def a.foo; end } end + SymbolsForEval = [ + :foo, + "dynsym_#{Random.rand(10000)}_#{Time.now}".to_sym + ] + + def test_instance_eval + bug11086 = '[ruby-core:68961] [Bug #11086]' + SymbolsForEval.each do |sym| + assert_nothing_raised(TypeError, sym, bug11086) { + sym.instance_eval {} + } + assert_raise(TypeError, sym, bug11086) { + sym.instance_eval {def foo; end} + } + end + end + + def test_instance_exec + bug11086 = '[ruby-core:68961] [Bug #11086]' + SymbolsForEval.each do |sym| + assert_nothing_raised(TypeError, sym, bug11086) { + sym.instance_exec {} + } + assert_raise(TypeError, sym, bug11086) { + sym.instance_exec {def foo; end} + } + end + end + def test_frozen_symbol assert_equal(true, :foo.frozen?) assert_equal(true, :each.frozen?) -- cgit v1.2.3