From: Trans Date: 2005-04-29T22:09:33+09:00 Subject: Re: instance/class_eval Bertram Scharpf wrote: > Hi, experts, > > how can I find out what my current class context is? > I say: > > class C ; end > C.instance_eval { def f ; "f" ; end } > C.f > #=> "f" > > class D ; end > D.class_eval { def f ; "f" ; end } > D.new.f > #=> "f" > > Obviously the method will be put into another context > either. I would like to be able to ask what the context is > _before_ I define the method. `self' seems to be the same in > both cases. > > Sorry, it's my itch that I want to know the whole truth. I assume you mean: C.instance_eval { self } == C.class_eval { self } And you are right, self is the same for both contexts. I believe the question is the same as asking if it is possible to detect the idioclass b/c the idioclass of the class_eval context is the instance_eval context. class C class << self # this is C.instance_eval { self } end # this is C.class_eval { self } end That being the case, see the new thread: determining when inside 'class << self'. T.