[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Shortcut for nested modules

John Ky

10/9/2006 12:30:00 PM

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::D
> def D.f
> end
> end

Thanks

-John

3 Answers

Austin Ziegler

10/9/2006 12:33:00 PM

0

On 10/9/06, John Ky <newhoggy@gmail.com> 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::D
> > def D.f
> > end
> > end

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

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

John Ky

10/9/2006 12:49:00 PM

0

Hi Austin,

This code doesn't work either:

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

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

Thanks

-John

On 10/9/06, Austin Ziegler <halostatue@gmail.com> wrote:
> > The following doesn't work for me:
> >
> > > module A::B::C::D
> > > def D.f
> > > end
> > > end
>
> That will work if A::B::C exist.

Paul Battley

10/9/2006 1:00:00 PM

0

On 09/10/06, John Ky <newhoggy@gmail.com> wrote:
> Hi Austin,
>
> This code doesn't work either:
>
> > module A; module B; module C
> > end; end; end
> >
> > module A::B::C::D
> > def D.f
> > end
> > end
>
> testns.rb:5: uninitialized constant A::B::C::D::D (NameError)

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

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

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

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

Paul.