If `main` is an instance of `Object`, why can't I call it?

前端 未结 3 941
鱼传尺愫
鱼传尺愫 2020-12-17 00:11

When I type self, I get a return value main. I made this test:

main2 = Object.new

Then I can call main2

3条回答
  •  别那么骄傲
    2020-12-17 01:14

    "What is the Ruby Top-Level?" is an article on the Ruby top level that explains everything you need to know.

    As an aside however, you can access main anywhere in your program by using TOPLEVEL_BINDING.eval('self').

提交回复
热议问题