Thomas Wieczorek
3/6/2008 2:13:00 PM
On Thu, Mar 6, 2008 at 2:37 PM, Chinna Karuppan
<chinnakaruppan@gmail.com> wrote:
> Hi,
> I am new to Ruby and This is a very basic question.when I type p self in
> irb it gives me 'main'.
>
I can't say much to the details, how irb is implemented, but you can
overwrite what "p object" returns, when you overwrite the inspect()
method:
class FooBar
end
p FooBar.new #=> #<FooBar:0x2aa50f8>
class FooBar
def inspect
"I am FooBar"
end
end
p FooBar.new #=> I am FooBar
> when I say class what is happening in the backend.since within a class
> end I am able to call define_method which is a private method and should
> never be available to anybody and another intersting thing is it is not
> accessible outside of the
> class.
You can use the send method to call private methods in Ruby 1.8.6, I
am not sure if it works in 1.9
class Baz
private
def hello; "HELLO!"; end
end
Baz.new.send(:hello) #=> "HELLO!"