Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Shortcut for nested modules

Reply
Thread Tools

Shortcut for nested modules

 
 
John Ky
Guest
Posts: n/a
 
      10-09-2006
Hello,

Is there a short cut for:

> module A; module B; module C; module D
> def D.f
> end
> end; end; end; end


The following doesn't work for me:

> module A::B::C:
> def D.f
> end
> end


Thanks

-John

 
Reply With Quote
 
 
 
 
Austin Ziegler
Guest
Posts: n/a
 
      10-09-2006
On 10/9/06, John Ky <> wrote:
> Hello,
>
> Is there a short cut for:
>
> > module A; module B; module C; module D
> > def D.f
> > end
> > end; end; end; end

>
> The following doesn't work for me:
>
> > module A::B::C:
> > def D.f
> > end
> > end


That will work if A::B::C exist.

-austin
--
Austin Ziegler * * http://www.halostatue.ca/
* * http://www.halostatue.ca/feed/
*

 
Reply With Quote
 
 
 
 
John Ky
Guest
Posts: n/a
 
      10-09-2006
Hi Austin,

This code doesn't work either:

> module A; module B; module C
> end; end; end
>
> module A::B::C:
> def D.f
> end
> end


testns.rb:5: uninitialized constant A::B::C:: (NameError)

Thanks

-John

On 10/9/06, Austin Ziegler <> wrote:
> > The following doesn't work for me:
> >
> > > module A::B::C:
> > > def D.f
> > > end
> > > end

>
> That will work if A::B::C exist.


 
Reply With Quote
 
Paul Battley
Guest
Posts: n/a
 
      10-09-2006
On 09/10/06, John Ky <> wrote:
> Hi Austin,
>
> This code doesn't work either:
>
> > module A; module B; module C
> > end; end; end
> >
> > module A::B::C:
> > def D.f
> > end
> > end

>
> testns.rb:5: uninitialized constant A::B::C:: (NameError)


It's the presence of D in the method name that's the problem; any of
these will work:

module A::B::C:
def self.f
puts 'foo'
end
end

module A::B::C:
def f
puts 'foo'
end
module_function :f
end

module A::B::C:
def f
puts 'foo'
end
extend self
end

Paul.

 
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
ipython shortcut to reload modules bernhard.voigt@gmail.com Python 1 02-21-2007 09:59 AM
Shortcut, And Re-Directing Of Shortcut Quest. ? Robert11 Computer Support 1 12-30-2004 03:13 PM
Importing modules from within other modules Tobiah Python 2 09-14-2003 09:18 PM
imputils - import problem modules from sys.modules Remy Cool Python 1 08-27-2003 02: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