This thread brought up an interesting idea in my mind. If one truly 
wants to define a top-level method, perhaps you could do this:

irb(main):001:0> class << self
irb(main):002:1>   def foo; puts "singleton method of top-level Object 
instance"; end
irb(main):003:1> end
=> nil
irb(main):004:0> foo
singleton method of top-level Object instance
=> nil
irb(main):005:0> Object.new.foo
NoMethodError: undefined method `foo' for #<Object:0x4c6dc>
         from (irb):5

The usefulness of this depends on what you want a top-level method for. 
If you want a globally accessible method, the foregoing approach 
doesn't work:

irb(main):006:0> class Demo
irb(main):007:1>   def bar; foo; end
irb(main):008:1> end
=> nil
irb(main):009:0> Demo.new.bar
NameError: undefined local variable or method `foo' for #<Demo:0x216e0>
         from (irb):7:in `bar'
         from (irb):9

But then, globally accessible methods are generally frowned upon in 
pure OO design. If, on the other hand, you're hacking out a quick 
script to do something useful, and you want a top-level method that 
only needs to be accessed at top-level, this works quite well *and* 
maintains good information hiding practice.

Just some random thoughts I had. Seems like I may have seen this 
before... is this an established idiom?

Pacem in terris / Mir / Shanti / Salaam / Heiwa
Kevin R. Bullock

On Jun 16, 2004, at 3:20 AM, ts wrote:

>  The glossary say, about main
>
> : ((:main:))
>
>     '((|((<self>))|))' at top level.
>
>     Since it can't be without self,
>     it is a mere ((<instance|Instance>)) of an ((<Object>)) class,
>     only for being there.
>     Some ((<singleton methods|Singleton Method>)) are defined
>     to operate the Object class.
>
>     Defined ((<singleton method|Singleton Method>)):
>
>      * private
>      * public
>      * include