From: Sebastian Krause Date: 2011-01-19T00:52:38+09:00 Subject: class context I thought that the block in the `class_exec`-method would be executed as if it appeared within a class definition. That seems naive as I discovered the following. Why does an error occur here? ---- irb(main):001:0> RUBY_VERSION => "1.9.2" irb(main):002:0> class C1; Const = 42; end => 42 irb(main):003:0> class C1; p Const; end 42 => 42 irb(main):004:0> C1.class_exec { p Const } NameError: uninitialized constant Class::Const from (irb):4:in `block in irb_binding' from (irb):4:in `class_exec' from (irb):4 from /usr/bin/irb:12:in `
' irb(main):005:0> C1.class_eval "p Const" # furthermore this 42 => 42 ----- Regards Sebastian