where nested methods go ?

Discussion in 'Ruby' started by Pietro Maggi, Sep 23, 2007.

  1. Pietro Maggi

    Pietro Maggi Guest

    Hi,
    I'm very new to ruby, so please forgive me if my question seems somehow
    silly.
    I typed the following code:

    class Myclass
    def m1
    def m2
    puts "m2"
    end
    end
    end

    a = Myclass.new
    a.m1
    a.m2

    b = Myclass.new
    b.m2

    which gives the following output:

    m1
    m2

    While it is clear to me where the m1 method goes (that is: in the class
    object referred by Myclass constant) I'm a bit confused on why also m2
    is in Myclass class object!

    I need some clarifications about it...

    tahnks!
    Pietro
    --
    Posted via http://www.ruby-forum.com/.
     
    Pietro Maggi, Sep 23, 2007
    #1
    1. Advertising

  2. Pietro Maggi

    Tim Hunter Guest

    Pietro Maggi wrote:

    > While it is clear to me where the m1 method goes (that is: in the class
    > object referred by Myclass constant) I'm a bit confused on why also m2
    > is in Myclass class object!
    >


    This question was thoroughly discussed in this thread:

    http://groups.google.com/group/comp...=gst&q=nested methods&rnum=2#b9b44e4fc8d19429

    --
    RMagick OS X Installer [http://rubyforge.org/projects/rmagick/]
    RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618]
    RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html]
     
    Tim Hunter, Sep 23, 2007
    #2
    1. Advertising

  3. Pietro Maggi

    Pietro Maggi Guest

    Pietro Maggi, Sep 23, 2007
    #3
    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. Russ Perry Jr
    Replies:
    2
    Views:
    4,288
    Russ Perry Jr
    Aug 20, 2004
  2. Chad E. Dollins
    Replies:
    3
    Views:
    682
    Kai-Uwe Bux
    Nov 8, 2005
  3. request@no_spam.com
    Replies:
    5
    Views:
    458
  4. Ultrus
    Replies:
    3
    Views:
    412
    Stefan Behnel
    Jul 9, 2007
  5. Kenneth McDonald
    Replies:
    5
    Views:
    379
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page