From: Patrick Hurley Date: 2005-12-22T19:05:44+09:00 Subject: Re: When are attr_reader type methods called? On 12/22/05, Vivek wrote: > class X > @ivar = 1 > def self.call_this > puts "call this" > @var = 1 > end > end > class A call_this > def some_method(arg) > puts arg > end > end > puts X.instance_eval { @var} > puts X.instance_eval { @ivar} > > > I have a statement like @var = 1 inside a class method 'call_this' > ,but @var is an instance variable,so who come I dont get an error? You are asking the right questions, if you are feeling adventurous do a quick: ri Class X is also an Object -- the variable @ivar is an instance variable in that class. Similarly the instance variable @var you create in the call_this method, becomes an instance variable in the class A. Try this: puts A.instance_eval { @var } # -> 1 Also note that if you: X.call_this puts X.instance_eval { @var } # -> 1 > And second > I read the documentation of instance_eval at The practical programmer > site..which says. > > instance_eval obj.instance_eval(aString [, file [ line ] ] ) -> > anObject > > But here and in Ross' examples we call it on a class ? Is the > documentation incorrect or am i missing something. You were (because I know you got it from my pitiful explanation :-) were missing that a Class is an Object. Good Luck and keep at it pth