From: Bertram Scharpf Date: 2007-02-08T22:06:58+09:00 Subject: Re: access to constants from instance_eval Hi, Am Donnerstag, 08. Feb 2007, 21:18:40 +0900 schrieb dblack@wobblini.net: > On Thu, 8 Feb 2007, David Chelimsky wrote: > > >irb(main):001:0> class Foo > >irb(main):002:1> BAR = "bar" > >irb(main):003:1> def bar > >irb(main):004:2> BAR > >irb(main):005:2> end > >irb(main):006:1> end > [...] > >irb(main):011:0> foo.instance_eval { BAR } > >NameError: uninitialized constant BAR > > foo doesn't have any constants; only Foo does. instance_eval changes > self, but it's still in the same scope. So the constants available > inside the block are the same as those available outside the block. `Scope' is not neccessarily "self": irb(main):001:0> class C ; X = "i" ; end => "i" irb(main):002:0> X = "o" => "o" irb(main):003:0> C.instance_eval { X } => "o" irb(main):004:0> C.class_eval { X } => "o" irb(main):005:0> C.instance_eval { self::X } => "i" irb(main):006:0> C.class_eval { self::X } => "i" irb(main):007:0> Is there a documentation that explains the differences between "scope", "context", "self" and whatelse? Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de