Issue #2788 has been updated by Marc-Andre Lafortune.


test-all also points out that `@@class_level_variable` would then refer to `NilClass`/`FalseClass`/`TrueClass`'s class variables, contrary to other singleton classes. This would be consistent with `class << nil` vs `class << my_string`.
----------------------------------------
Bug #2788: nil.instance_eval pushes nil onto cref
https://bugs.ruby-lang.org/issues/2788

Author: Shugo Maeda
Status: Assigned
Priority: Low
Assignee: Koichi Sasada
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.2dev (2010-02-18 trunk 26704) [i686-linux]


=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 `<main>'
 
 The behavior is the same in Ruby 1.8.7.
 Is it intended or a bug?
=end



-- 
http://bugs.ruby-lang.org/