Shortcut for nested modules

Discussion in 'Ruby' started by John Ky, Oct 9, 2006.

  1. John Ky

    John Ky Guest

    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
     
    John Ky, Oct 9, 2006
    #1
    1. Advertising

  2. 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::D
    > > 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/
    *
     
    Austin Ziegler, Oct 9, 2006
    #2
    1. Advertising

  3. John Ky

    John Ky Guest

    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 <> 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.
     
    John Ky, Oct 9, 2006
    #3
  4. John Ky

    Paul Battley Guest

    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::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.
     
    Paul Battley, Oct 9, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Remy Cool
    Replies:
    1
    Views:
    438
    Remy Cool
    Aug 27, 2003
  2. Tobiah
    Replies:
    2
    Views:
    320
    Tobiah
    Sep 14, 2003
  3. Ben Weintraub

    Disabling modules using Modules/Setup

    Ben Weintraub, Sep 9, 2006, in forum: Python
    Replies:
    0
    Views:
    359
    Ben Weintraub
    Sep 9, 2006
  4. Replies:
    1
    Views:
    520
    Jordan Greenberg
    Feb 21, 2007
  5. Peter Peyman Puk

    Importing v reloading modules modules

    Peter Peyman Puk, Mar 19, 2010, in forum: Python
    Replies:
    0
    Views:
    310
    Peter Peyman Puk
    Mar 19, 2010
Loading...

Share This Page