Hello,
I understand that everything in ruby is an object so a method defined
in a file like this in a file
def meth1
puts self
end
actually prints main.
but when I run it in the debugger mode and do main.methods. I get
‘main’ undefined variable…but If i do self.methods I can see the
methods but cant see the meth1 method.I thought ruby opens the ‘main’
object and adds methods to that instance.
So whats happening here?
Vivek
but If i do self.methods I can see the
methods but cant see the meth1 method.I thought ruby opens the ‘main’
object and adds methods to that instance.
So whats happening here?
You don’t get to see private methods - and methods defined on top level
are implicitely private:
15:56:46 [~]: ruby -e ‘def foo() puts “x” end; self.foo()’
-e:1: private method `foo’ called for main:Object (NoMethodError)