[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby help

Sunny Bogawat

8/20/2008 10:14:00 AM

Can someone enlighten me about

* Public Instance Methods.
* Public Class Methods.
* What is the root class for all Ruby Classes if there is one.
--
Posted via http://www.ruby-....

1 Answer

James Coglan

8/20/2008 11:45:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

2008/8/20 Sunny Bogawat <sunny_bogawat@neovasolutions.com>

> Can someone enlighten me about
>
> * Public Instance Methods.
> * Public Class Methods.
> * What is the root class for all Ruby Classes if there is one.



This is a little vague, but I'll try to help. In Ruby, Object is the root
class, and all classes (even Object) are instances of the Class class. Class
inherits from Module, which inherits from Object.

Object
^
|
Module
^
|
Class

So Object, Module and Class are all Classes, and are also all Objects. Hope
that makes sense.

Public instance methods are defined within a class and can be called on
instances of the class:

class Foo
def talk
'talking'
end
end

f = Foo.new
f.talk #=> 'talking'

Class methods are defined on the class itself (notice the use of self):

class Foo
def self.something
self.name
end
end

Foo.something #=> 'Foo'

'Public' just means that a method can be called from outside the object by
any other piece of code. Private methods can only be called inside an object
by other methods in the same class.