Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Learning newb: regaring methods and class methods

Reply
Thread Tools

Learning newb: regaring methods and class methods

 
 
Dominic Son
Guest
Posts: n/a
 
      07-12-2006
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/.

 
Reply With Quote
 
 
 
 
dblack@wobblini.net
Guest
Posts: n/a
 
      07-12-2006
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
http://www.velocityreviews.com/forums/(E-Mail Removed) => me

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling class methods from class methods, help? Oltmans Python 6 03-11-2009 07:59 PM
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Help Urgent:-Regaring Brainbench C++ questions Gurmeet C++ 2 07-06-2006 04:57 PM
Learning C and Learning Make/Configure/Building/Linking Hal Vaughan C Programming 7 03-21-2006 05:07 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM



Advertisments