Blrgh! Thanks, Mark & David. I have been schooled.

> My interpretation is that only
> methods whose definitions start in the outermost scope are made into
> private methods of Object.

Indeed, that's my impression now, too. I also know now that the magical 
top-level Object does not have a singleton class:

> a = ""
> class << a; def foo; def y; puts 'yo'; end end end
> a.foo
> a.y
> "hello".y
> __END__
> yo
> -:5: undefined method `y' for "hello":String (NoMethodError)

or, well, act like it.

Devin

David A. Black wrote:

>> irb(main):001:0> def moo; puts 'moo' end
>> => nil
>> irb(main):002:0> nil.moo
>> moo
>> => nil
>
>
> As Mark says, that's an IRB thing.  In Ruby itself:
>
>   $ ruby -e 'def x; end; nil.x'
>   -e:1: private method `x' called for nil:NilClass (NoMethodError)
>
> And, just for reference:
>
>   $ ruby -e 'def x; def y; p 1; end; end; x; nil.y'
>   1
>
> Since def's start a new local scope, I think it's reasonable to
> describe "def y" as not being lexically top-level (which I wouldn't if
> it were, say, inside an if statement rather than another def).  We can
> in any case call it "outermost scope".  My interpretation is that only
> methods whose definitions start in the outermost scope are made into
> private methods of Object.
>
>
> David
>