Ruby help

Can someone enlighten me about

* Public Instance Methods.
* Public Class Methods.
* What is the root class for all Ruby Classes if there is one.

2008/8/20 Sunny B. [email protected]

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs