Problem with Module/Class name resolution

Discussion in 'Ruby' started by Thomas Leitner, Feb 19, 2007.

  1. Hi,

    consider the following:

    module A
    X = 1
    end

    p A::X # => 1

    module B
    include A
    end

    p B::X # => 1

    module A
    module Help
    p X # => 1
    end
    end

    module B
    module Help
    p X # => NameError: uninitialized constant B::Help::X
    end
    end


    Why does referencing X from A, B, and A::Help work but not from
    B::Help although A is included in B? Is there a work-around to make
    this work?

    Bye,
    Thomas
    Thomas Leitner, Feb 19, 2007
    #1
    1. Advertising

  2. Thomas Leitner

    SonOfLilit Guest

    To expand the knowledge on this weirdness:

    irb(main):001:0> module A
    irb(main):002:1> module H
    irb(main):003:2> end
    irb(main):004:1> end
    => nil
    irb(main):005:0> module B
    irb(main):006:1> include A
    irb(main):007:1> end
    => B
    irb(main):008:0> module B
    irb(main):009:1> module H
    irb(main):010:2> end
    irb(main):011:1> end
    => nil
    irb(main):012:0> A::H.object_id == B::H.object_id
    => false
    irb(main):014:0> B::H
    => B::H # it exists
    SonOfLilit, Feb 19, 2007
    #2
    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. Andrew FPGA
    Replies:
    0
    Views:
    954
    Andrew FPGA
    Sep 26, 2005
  2. Shadow Lynx
    Replies:
    1
    Views:
    2,987
    Christopher Reed
    Feb 4, 2006
  3. Haoyu Zhang

    Function Name Resolution Problem

    Haoyu Zhang, Nov 3, 2003, in forum: Python
    Replies:
    1
    Views:
    382
    Alex Martelli
    Nov 4, 2003
  4. Replies:
    2
    Views:
    316
    Marcus Kwok
    Nov 27, 2006
  5. rocky
    Replies:
    2
    Views:
    310
    rocky
    Jul 7, 2009
Loading...

Share This Page