ActionsLike0
Bug #2788
closednil.instance_eval pushes nil onto cref
Description
=begin
A singleton class definition of nil pushes NilClass onto cref.
It is reasonable because NilClass has nil as the only instance.
However, nil.instance_eval pushes nil onto cref, which means that method definitions are not permitted in that context.
defiant:ruby$ ruby-trunk -ve 'class <<nil; def foo; puts "foo" end; end; nil.foo'
ruby 1.9.2dev (2010-02-18 trunk 26704) [i686-linux]
foo
defiant:ruby$ ruby-trunk -ve 'nil.instance_eval {|i| def foo; puts "foo" end }; nil.foo'
ruby 1.9.2dev (2010-02-18 trunk 26704) [i686-linux]
-e:1:in block in <main>': no class/module to add method (TypeError) from -e:1:in
instance_eval'
from -e:1:in `'
The behavior is the same in Ruby 1.8.7.
Is it intended or a bug?
=end
Updated by akr (Akira Tanaka) almost 14 years ago
- Project changed from 8 to Ruby
- Category changed from core to core
Updated by marcandre (Marc-Andre Lafortune) about 13 years ago
- Assignee changed from matz (Yukihiro Matsumoto) to ko1 (Koichi Sasada)
- Target version set to 2.0.0
Updated by ko1 (Koichi Sasada) almost 13 years ago
- Assignee changed from ko1 (Koichi Sasada) to matz (Yukihiro Matsumoto)
Updated by ko1 (Koichi Sasada) over 12 years ago
- Assignee changed from matz (Yukihiro Matsumoto) to nobu (Nobuyoshi Nakada)
Updated by nobu (Nobuyoshi Nakada) over 12 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
ActionsLike0