From: Dat Nguyen Date: 2001-08-04T01:02:25+09:00 Subject: [ruby-talk:19080] Re: a+, a++, a+++, a++++, a+ ---, a + ***



>From: Dave Thomas
>Reply-To: ruby-talk@ruby-lang.org
>To: ruby-talk@ruby-lang.org (ruby-talk ML)
>Subject: [ruby-talk:19076] Re: a+, a++, a+++, a++++, a+ ---, a + ***
>Date: Sat, 4 Aug 2001 00:17:05 +0900
>
>"Dat Nguyen" writes:
>
> > a = 0                # => 0
> >
> > a+ 1                 # => 1
> >
> > a++ 1               # => 1
> >
> > a+++ 1             # => 1
> >
> > a+ ++++++ 1   # => 1
> >
> > a + --- 3           #=>
> >
> > a + *** 3         #=> SyntaxError: compile error
> > (irb):28: parse error
> >
> > Why?
>
>Because '+' is both a unary and a binary operator, and '*' isn't.
>
>Now, for extra credit, why is this OK
>

> a+ 1

a.+(1)

>
>and this isn't:
>

> a +1

sending to the root object the message "a +1" does not fail if the following was defined:

def a(b)

end

but the next question raised. I cannot override the above with:

def a(b, c)

end

and expect:

a +1

or

a  2  3

to work. The list of args is different. Why doesn't it work?

Regards

Dat

>
>Regards
>
>
>Dave


Get your FREE download of MSN Explorer at http://explorer.msn.com