Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在下面的示例中,函数 foo 不在任何类中,在这种情况下,“我是”哪个类的实例?
def foo () @i = "hello world" end foo puts @i
foo属于Object:
foo
Object
def foo @i = "hello world" end Object.instance_methods(false) # => [:foo] method(:foo).owner # => Object