mirror of
https://github.com/ruby/ruby.git
synced 2025-09-24 04:54:01 +02:00
* compile.c (compile_cpath, iseq_compile_each): reverted
constant/class variable lookup in instance_eval etc. to the behavior of 1.8. * eval.c (rb_mod_nesting): ditto. * insns.def (putspecialobject, defineclass): ditto. * node.h (NODE_FL_CREF_PUSHED_BY_EVAL): ditto. * vm_core.h (VM_SPECIAL_OBJECT_CONST_BASE): ditto. * vm_eval.c (yield_under, eval_under): ditto. * vm_insnhelper.c (vm_cref_push, vm_get_const_base, vm_get_ev_const, vm_get_cvar_base): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9998481d4e
commit
7dbfe89630
10 changed files with 105 additions and 22 deletions
|
@ -216,10 +216,29 @@ class TestModule < Test::Unit::TestCase
|
|||
remove_rake_mixins(remove_json_mixins(remove_pp_mixins(String.ancestors))))
|
||||
end
|
||||
|
||||
CLASS_EVAL = 2
|
||||
@@class_eval = 'b'
|
||||
|
||||
def test_class_eval
|
||||
Other.class_eval("CLASS_EVAL = 1")
|
||||
assert_equal(1, Other::CLASS_EVAL)
|
||||
assert(Other.constants.include?(:CLASS_EVAL))
|
||||
assert_equal(2, Other.class_eval { CLASS_EVAL })
|
||||
|
||||
Other.class_eval("@@class_eval = 'a'")
|
||||
assert_equal('a', Other.class_variable_get(:@@class_eval))
|
||||
assert_equal('b', Other.class_eval { @@class_eval })
|
||||
|
||||
Other.class_eval do
|
||||
module_function
|
||||
|
||||
def class_eval_test
|
||||
"foo"
|
||||
end
|
||||
end
|
||||
assert("foo", Other.class_eval_test)
|
||||
|
||||
assert_equal([Other], Other.class_eval { |*args| args })
|
||||
end
|
||||
|
||||
def test_const_defined?
|
||||
|
@ -451,7 +470,7 @@ class TestModule < Test::Unit::TestCase
|
|||
|
||||
def test_class_variable_get
|
||||
c = Class.new
|
||||
c.class_eval { @@foo = :foo }
|
||||
c.class_eval('@@foo = :foo')
|
||||
assert_equal(:foo, c.class_variable_get(:@@foo))
|
||||
assert_raise(NameError) { c.class_variable_get(:@@bar) } # c.f. instance_variable_get
|
||||
assert_raise(NameError) { c.class_variable_get(:foo) }
|
||||
|
@ -460,13 +479,13 @@ class TestModule < Test::Unit::TestCase
|
|||
def test_class_variable_set
|
||||
c = Class.new
|
||||
c.class_variable_set(:@@foo, :foo)
|
||||
assert_equal(:foo, c.class_eval { @@foo })
|
||||
assert_equal(:foo, c.class_eval('@@foo'))
|
||||
assert_raise(NameError) { c.class_variable_set(:foo, 1) }
|
||||
end
|
||||
|
||||
def test_class_variable_defined
|
||||
c = Class.new
|
||||
c.class_eval { @@foo = :foo }
|
||||
c.class_eval('@@foo = :foo')
|
||||
assert_equal(true, c.class_variable_defined?(:@@foo))
|
||||
assert_equal(false, c.class_variable_defined?(:@@bar))
|
||||
assert_raise(NameError) { c.class_variable_defined?(:foo) }
|
||||
|
@ -474,7 +493,7 @@ class TestModule < Test::Unit::TestCase
|
|||
|
||||
def test_remove_class_variable
|
||||
c = Class.new
|
||||
c.class_eval { @@foo = :foo }
|
||||
c.class_eval('@@foo = :foo')
|
||||
c.class_eval { remove_class_variable(:@@foo) }
|
||||
assert_equal(false, c.class_variable_defined?(:@@foo))
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue