First of all, class methods of class Foo in ruby is methods defined on
the class Foo -- an instance of class Class --, and is not on an
instance of class Foo.  Unlike C++ or Java, those can't be called in a
function-like form since they are *NOT* belong to *AN INSTANCE OF* Foo.


In message <8hrt8j$niv$1 / nnrp1.deja.com>
hal9000 / hypermetrics.com writes:

> I was trying to create an object that could be added
> to itself. I tried to implement the + operator, and
> I discovered that I could not invoke "new" from
> within the class -- see line (e). I assume this is
> a feature -- but why?

Use "Wocka.new" instead.  The reason is above -- new is a class
method.


> defined on line (a), outside the class.

This is simply because (a) does not omit receiver.


> Since I implemented the + operator, the += operator
> should have been created for me. (And it was, as I
> confirmed.)

Operators like "+=" is merely a syntax sugar of "foo = foo+bar".  A
real method called are "+".


> Line (i) requires parens -- not sure why -- see line (j).
> This tells me Wocka::+ is NOT defined.
> 
> Line (l) tells me that x.+ is defined.

Sure.


> The same attempts on Wocka::+= and x.+= (see lines (k)
> and (m)) both result in syntax errors.

And this is also reasonable.  You can not define operator "=" and
such, so it is natural the parser can not parse `unnatural
expression'.


-- 
kjana / os.xaxon.ne.jp                                  June 10, 2000
Slow and steady wins the race.