From: Robert Klemme Date: 2007-05-04T03:35:04+09:00 Subject: Re: Top-level On 03.05.2007 20:13, Lucas Holland wrote: > I'm currently diving a bit deeper into Ruby and I've already asked this > question in the IRC (the folks there have been great I think I'm getting > it 50%). The question's about top-level methods: > > Let's take puts as an example. Puts is inside of the Kernel module, > which gets mixed into the Object class. So essentially, it's a private > method of Object. When I call puts, I don't specify a receiver, so self > is assumed (I think so). Correct. > In this case self refers to main, an instance > of Object, automatically created. So, I'm really calling main.puts. main > is an instance of Object, so why is it able to call private methods of > Object? Um, you explained it already: "puts" is an *instance* method of Object. And since "main" is an instance of Object or one of its subclasses (all classes are subclasses of Object!) it has method "puts". Basically the method is only defined private in order to enforce a more function like invocation: irb(main):001:0> self.puts "foo" NoMethodError: private method `puts' called for main:Object from (irb):1 from :0 irb(main):002:0> puts "foo" foo => nil irb(main):003:0> Kind regards robert