Guillaume Cottenceau <gc / mandrakesoft.com> writes:

> My question is, why is it so? Maybe Matz thought that the most common case
> in adding one small method in the top-level would be a Class method rather
> than an Instance method. While I would think the contrary :-). 

Not wishing to speak for Matz, but I can take a stab at the reason:
consistency.

When you say

   def x.y
     # body
   end

You are saying that object 'x' will respond to message 'y' by doing
'body'.

  a = "hello"
  def a.length
    99
  end

  puts a.length


  def String.wombat
    puts "Marsupial"
  end

  String.wombat



In both cases, the method definition matches the usage. Having

  def String.wombat

define an instance method of class String would not be consistent with
this.


Regards


Dave