ruby picture

RCR 220: Automatic completion of Namespace

Submitted by rolo (Tue Feb 24 10:02:57 UTC 2004)

Abstract

There is a need to oraganize libraries with depths more 1. This tree can become quite deep. (depth > 3). To always write a fully qualified name is laborious task.

Problem

Example:

require 'Mycompany/Net/Pop'
headers = Mycompany::Net::Pop::Command.top()

It is easier to use just

require 'Mycompany/Net/Pop'
headers = Command.top()

Proposal

Allow ruby require statement to resolve namespaces.

Analysis

No Idea. Can Anybody help!

Implementation

ruby picture
Comments Current voting

I think that's literally impossible. If you require two features that both have Command classes, there's no possibility of resolution.

I would recommend:

require 'Mycompany/Net/Pop'
include Mycompany::Net::Pop

Then Command will be part of the current namespace.

-- David Black


I think that's literally impossible. If you require two features that both have Command classes, there's no possibility of resolution.

Not Really. Conflicts can be handled by using fully qualified name. Anyway how can using include help this.

-- rolo [Rohit Lodha]


Consider this:

require 'A/B/C'
require 'D/E/C'
What is C.new at this point? And does it change, depending on the order? Or depending on whether you rewrite the code and remove something?

As for include... what it does is eliminate the need to use the fully-qualified path. That was your goal, wasn't it? :-)

-- David Black


It's also possible to do this with simple assignment, since modules are simply objects.

require 'Mycompany/Net/Pop'
cmd = Mycompany::Net::Pop::Commands
headers = cmd.top

This way, you can even have David's example:

require 'A/B/C'
require 'D/E/C'
abc = A::B::C dec = D::E::C

-austin


Strongly opposed 3
Opposed 1
Neutral 0
In favor 0
Strongly advocate 0
ruby picture

This RCR has been superseded by RCR 221.

ruby picture

Powered by .