[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

include semantics broken?

Bob Sidebotham

10/16/2004 1:27:00 AM

This seems very odd to me:

module A
module B
end
end

module X
include A
module Y
B # => uninitialized constant X::Y::B (NameError
end
end

If I move the "include A" either up one line (before "module X"), or
down one line (after "module Y"), then it works as expected. Since
include is supposed to import all the constants from one module to the
other, then surely this should make the constants of A available to
anything defined within X?

My intent, in doing this, is to include A's semantics only where they
are relevant...

This may or may not be the way it's supposed to work--but for me, it
does violate POLS.

Puzzled,
Bob Sidebotham
1 Answer

Brian Schröder

10/17/2004 11:03:00 PM

0

Bob Sidebotham wrote:
> This seems very odd to me:
>
> module A
> module B
> end
> end
>
> module X
> include A
> module Y
> B # => uninitialized constant X::Y::B (NameError
> end
> end
>
> If I move the "include A" either up one line (before "module X"), or
> down one line (after "module Y"), then it works as expected. Since
> include is supposed to import all the constants from one module to the
> other, then surely this should make the constants of A available to
> anything defined within X?
>
> My intent, in doing this, is to include A's semantics only where they
> are relevant...
>
> This may or may not be the way it's supposed to work--but for me, it
> does violate POLS.
>
> Puzzled,
> Bob Sidebotham
>

You can tell ruby to start from the "root"-namespace by prefixing with a
::. See below:

module A
module B
end
end

module X
include A
module Y
::A::B # => uninitialized constant X::Y::B (NameError
end
end

Regards,

Brian
--
Brian Schröder
http://ruby.brian-sch...