Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Module Scopes and Names

Reply
Thread Tools

Module Scopes and Names

 
 
Brian Schroeder
Guest
Posts: n/a
 
      08-24-2004
Hello Group,

I think that ruby is a bit too intelligent regarding module names.
Consider the follwing situation

module B
class B; end
end

module A
module B
module C
class C < B::B; end
end
end
end

This does not work, as ruby tries to load A::B::B instead of B::B as
I supposed. So for example I can't create a class structure

module MyProg
module UI
module Gnome
class Something < Gnome::Canvas
end
end
end

even though this would seem a natural naming scheme to me.

What is the reason behind this behaviour, and is it possible to avoid
this problem without renaming my module to MyProg::UI::GnomeUI which
seems redundant to me?

regards,

Brian Schröder

--
Brian Schröder
http://www.brian-schroeder.de/
http://ruby.brian-schroeder.de/
 
Reply With Quote
 
 
 
 
T. Onoma
Guest
Posts: n/a
 
      08-24-2004
On Tuesday 24 August 2004 07:01 am, Brian Schroeder wrote:
module B
class B; end
end

module A
module B
module C
class C < ::B::B; end
end
end
end


(I think, but never have tried)

--
T.


 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      08-24-2004

"Brian Schroeder" <> schrieb im Newsbeitrag
news. ..
> Hello Group,
>
> I think that ruby is a bit too intelligent regarding module names.


No, that's usual scope resolution practice as found in other languages (C++
etc.). Module resolution starts always at the nearest possible position,
which makes perfectly sense since it saves a lot of typing for the usual
case, i.e. when you want to refer to something in a sibling module.

> Consider the follwing situation
>
> module B
> class B; end
> end
>
> module A
> module B
> module C
> class C < B::B; end


As Mr. T already pointed out use the form ::B::B to explicitely start lookup
from the top level.

> end
> end
> end
>
> This does not work, as ruby tries to load A::B::B instead of B::B as
> I supposed. So for example I can't create a class structure
>
> module MyProg
> module UI
> module Gnome
> class Something < Gnome::Canvas
> end
> end
> end
>
> even though this would seem a natural naming scheme to me.
>
> What is the reason behind this behaviour, and is it possible to avoid
> this problem without renaming my module to MyProg::UI::GnomeUI which
> seems redundant to me?


See above.

Regards

robert

 
Reply With Quote
 
Brian Schroeder
Guest
Posts: n/a
 
      08-24-2004
> As Mr. T already pointed out use the form ::B::B to explicitely start
> lookup from the top level.


Thank you all for the replies. This was a very helpful information. I just never
read that ::X::Y starts at the top level - so as always it was not ruby too
intelligent, but I missed the important point.

regards,

Brian


--
Brian Schröder
http://www.brian-schroeder.de/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Same variable names inside multiple sub-scopes results in delete tocrash sporadically pvinodhkumar@gmail.com C++ 12 10-07-2012 03:19 PM
Digiscoping Acuter and Celestron Spotting Scopes and Zenith BiolamMicroscopes with Canon Powershot A590 IS Civet Digital Photography 0 08-18-2009 11:00 AM
Digiscoping Acuter and Celestron Spotting Scopes and Zenith BiolamMicroscopes with Canon Powershot A590 IS Civet Digital Photography 0 08-17-2009 09:53 PM
Digiscoping Acuter and Celestron Spotting Scopes and Zenith BiolamMicroscopes with Canon Powershot A590 IS Civet Digital Photography 0 08-17-2009 08:51 PM
Digiscoping Acuter and Celestron Spotting Scopes and Zenith BiolamMicroscopes with Canon Powershot A590 IS Civet Digital Photography 1 08-17-2009 03:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57