reopening classes in modules ?

Discussion in 'Ruby' started by ako..., Jan 27, 2006.

  1. ako...

    ako... Guest

    hello,

    module M
    class C
    def c() puts 'c' end
    end
    end

    module M
    class C
    def c() puts 'cc' end
    end
    end

    M::C.new.c

    produces the same output as

    module M
    class C
    def c() puts 'c' end
    end
    end

    class M::C
    def c() puts 'cc' end
    end

    M::C.new.c


    does anyone know what the difference is between reopening a module and
    then reopening a class in it as in the first code fragment and just
    reopening a class defined in a module as in the second fragment?

    as far as i can tell there is some difference because my real code
    which is more complicated than the above works in case when i reopen
    M::C and does not work in case when i reopen M and then reopen C.

    thanks
    konstantin
     
    ako..., Jan 27, 2006
    #1
    1. Advertising

  2. ako...

    George Ogata Guest

    "ako..." <> writes:

    > does anyone know what the difference is between reopening a module and
    > then reopening a class in it as in the first code fragment and just
    > reopening a class defined in a module as in the second fragment?


    Scoping?:

    class X
    end

    module M
    class X
    end

    class C
    def foo
    puts X.name
    end
    end
    end


    class M::C
    def bar
    puts X.name
    end
    end

    mc = M::C.new
    mc.foo # => M::X
    mc.bar # => X
     
    George Ogata, Jan 28, 2006
    #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. Lloyd Sheen

    Reopening project loses <PARAM's

    Lloyd Sheen, Nov 18, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    352
    Lloyd Sheen
    Nov 18, 2003
  2. T Driver

    Re-reading a Stream without reopening

    T Driver, Jun 5, 2007, in forum: ASP .Net
    Replies:
    8
    Views:
    404
    T Driver
    Jun 7, 2007
  3. Tomas Mikula
    Replies:
    7
    Views:
    469
    Andreas Leitgeb
    Nov 15, 2007
  4. Logan Capaldo
    Replies:
    0
    Views:
    149
    Logan Capaldo
    Aug 13, 2006
  5. Reopening Classes

    , Oct 25, 2006, in forum: Ruby
    Replies:
    7
    Views:
    144
Loading...

Share This Page