From: Daniel Brockman Date: 2005-07-20T00:23:46+09:00 Subject: Re: Ruby/Rails as a starter language? Mark Volkmann writes: > On 7/19/05, Stefan Lang wrote: > >> There are no static methods in Ruby >> (there is always a "self") > > Is there some difference between what is called a "class > method" in Ruby and what is called a "static method" in > Java? They seem the same to me. In Ruby, “class methods” aren't static — they are dispatched on the receiver like other methods and are thus polymorphic. class Moomin { public static int foo() { return 123; } } Moomin.foo(); //=> 123 That method isn't really a method. It's just a function, because it doesn't have a receiver. The above Java code is equivalent to the below C code: int Moomin_foo (void) { return 123; } So Moomin is not the receiver — it's just the namespace. Now look at this Ruby code: class Snufkin def self.foo ; 123 end end Snufkin.foo #=> 123 Here, Snufkin is an object and ‘foo’ is a method. It works just like any other method invocation in Ruby. To see where this matters, try to reproduce the below code in Java: def polymorph(snufkin) snufkin.foo end polymorph Snufkin #=> 123 class Snork def self.foo ; 456 end end polymorph Snork #=> 456 -- Daniel Brockman So really, we all have to ask ourselves: Am I waiting for RMS to do this? --TTN.