From: Hal Fulton Date: 2004-06-22T04:54:13+09:00 Subject: Re: About top-level method Sam Sungshik Kong wrote: > If I understand correctly, one can't call a private method via object name > (receiver). > Private methods can be called only with self. > > So the following code will cause an error (at the top level). > > def foo #->this is a private instance method of Object > ... > end > > obj = Object.new > > obj.foo #->Error, but in irb, it's ok. > > Best explanation so far is that irb makes an exception for debugging > purpose. No, I don't think that's quite right. My guess would be that when you're in an irb session, you're not really at the top level. Imagine something like: obj.instance_eval do # User commands... end In other words, I think it's a side effect of the way irb works -- neither a bug nor a feature as such, and not a special exception deliberately built in. That's just my impression. I haven't proved it. Hal