[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Module.nesting and module_eval

Brian Mitchell

4/1/2005 9:46:00 PM

I was wondering why Module.nesting is not consitent when called from
module_eval:

class Object
def Object.inherited(sub)
p sub.module_eval { Module.nesting } # [Object]
p sub.module_eval("Module.nesting") # [A::B, Object]
end
end

module A
class B
p Module.nesting # [A::B, A] OK
end
p Module.nesting # [A] OK
end

The evals inside of Object.inherited don't return the same thing. I
think I understand why, classes are objects that can be shared across
bindings but how would I go about fixing this without touching any of
"module A ... end"?

Thanks.

Brian.


1 Answer

Yukihiro Matsumoto

4/2/2005 11:57:00 AM

0

Hi,

In message "Re: Module.nesting and module_eval"
on Sat, 2 Apr 2005 06:46:26 +0900, Brian Mitchell <binary42@gmail.com> writes:

|I was wondering why Module.nesting is not consitent when called from
|module_eval:

Module.nesting uses compile time information if it's available. The
nesting information is not available from within eval and its family
with string, so it tries its best (i.e. [A::B, Object]).

matz.