but when I run it in the debugger mode and do main.methods. I get
‘main’ undefined variable…
The fact that self when printed shows “main” does not mean that there is
variable with that name. You can make anything print main:
15:57:02 [~]: ruby -e ‘o=Object.new; def o.to_s() “main” end; puts o’
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)
15:56:58 [~]: ruby -e ‘def foo() puts “x” end; foo()’
15:54:57 [~]: ruby -e ‘def foo() end; p
15:57:44 [~]: ruby -e ‘def foo() end; p private_methods.grep(/foo/)’