Learning newb: regaring methods and class methods

Discussion in 'Ruby' started by Dominic Son, Jul 12, 2006.

  1. Dominic Son

    Dominic Son Guest

    hi, i just need to know if i'm on the right trax regarding ruby:

    a '::' method class attached to another constant or variable will tell
    that constant/variable to use all methods under it's class where

    as '.' tells ruby to use only 1 method.

    but before using that method, we have to call for the 'new class' that
    method belongs to...

    Can someone please tell me if any of the above is wrong?

    thanks

    --
    Posted via http://www.ruby-forum.com/.
     
    Dominic Son, Jul 12, 2006
    #1
    1. Advertising

  2. Dominic Son

    Guest

    Hi --

    On Thu, 13 Jul 2006, Dominic Son wrote:

    > hi, i just need to know if i'm on the right trax regarding ruby:
    >
    > a '::' method class attached to another constant or variable will tell
    > that constant/variable to use all methods under it's class where
    >
    > as '.' tells ruby to use only 1 method.
    >
    > but before using that method, we have to call for the 'new class' that
    > method belongs to...
    >
    > Can someone please tell me if any of the above is wrong?


    :: is chiefly for navigating paths through nested classes and modules:

    class A
    module B
    class C
    end
    end
    end

    A::B::C.new # new instance of the inner class

    is for calling methods -- like C.new, above.

    You'll sometimes see :: used for calling methods when the receiver is
    a class or module, but personally I think it's simpler and clearer just
    to use . for calling methods.


    David

    --
    http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
    http://www.manning.com/black => RUBY FOR RAILS, the Ruby book for
    Rails developers
    http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log
    => me
     
    , Jul 12, 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. Hal Vaughan
    Replies:
    7
    Views:
    494
  2. Gurmeet
    Replies:
    2
    Views:
    2,537
  3. Art Gillespie
    Replies:
    5
    Views:
    142
    Robert Klemme
    Oct 8, 2005
  4. Kenneth McDonald
    Replies:
    5
    Views:
    344
    Kenneth McDonald
    Sep 26, 2008
  5. Andrey Popp

    [I'm learning C]: Learning to use ucontext

    Andrey Popp, Jan 29, 2012, in forum: C Programming
    Replies:
    5
    Views:
    768
    Keith Thompson
    Jan 31, 2012
Loading...

Share This Page