On Wed, Dec 04, 2002 at 07:22:42PM +0900, ts wrote:
> >>>>> "M" == Mauricio =?iso-8859-1?Q?Fern=E1ndez?= <Mauricio> writes:
> 
> M> true nature (as singleton methods of the top-level object).
> 
>  You have only 4 methods in your version of ruby :-))
> 

As usual, you're right:
batsman@tux-chan:/tmp$ cat b.rb
p self.class
p self.singleton_methods.sort
def hello
        puts "Hello, World!"
end
hello
p self.singleton_methods.sort
self.private_methods.grep(/hello/) { puts "=> private method" }
Object.new.private_methods.grep(/hello/) { puts "=> private method of Object.new" }

batsman@tux-chan:/tmp$ ruby b.rb
Object
["include", "private", "public", "to_s"]
Hello, World!
["include", "private", "public", "to_s"]
=> private method
=> private method of Object.new

I was quite surprised to see #hello defined as a private method in class
Object (and hence inherited by all the objects!) And even more when I
saw that the "private" hello is shadowed.

irb(main):001:0> class A
irb(main):002:1> def do
irb(main):003:2> hello
irb(main):004:2> end
irb(main):005:1> def hello
irb(main):006:2> puts "A#hello"
irb(main):007:2> end
irb(main):008:1> end
nil
irb(main):009:0> def hello
irb(main):010:1> puts "top level"
irb(main):011:1> end
nil
irb(main):012:0> A.new.do
A#hello
nil

The end result is the same, but it really feels cleaner IMHO if the
method is defined only in the top-level object as a singleton. As I feel
it is "cleaner", I couldn't help thinking that Ruby behaved this way :)

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Win95 is not a virus; a virus does something.
	-- unknown source