Re: Please don't flame me...why is there no "++" in Ruby again ?
- From: David Masover <ninja@xxxxxxxxxxxx>
- Date: Fri, 29 Aug 2008 00:27:27 -0500
On Thursday 28 August 2008 16:25:59 Joel VanderWerf wrote:
John Pritchard-williams wrote:
I did check my Ruby books by the way, but they just "unlike C there is
no ++ operator in Ruby...." :)
In ruby, operators are methods and they operate on objects, not on
variables.
That's not really a valid reason, and not entirely true -- there is no +=
method for you to define. It behaves as though it's a macro:
foo += 1
#becomes
foo = foo + 1
I see no reason there couldn't be a ++ operator that behaves the same way:
foo ++
# becomes
foo += 1
# or, probably better:
foo = foo.succ
You can define foo=, and you can define +, but you can't define +=.
Why not add a ++ that works the same way += does?
... Then again, why pollute our namespace with an operator that would see so
little use? I can't remember the last time I had to use "+=1" in Ruby.
.
- Follow-Ups:
- Re: Please don't flame me...why is there no "++" in Ruby again ?
- From: Roger Pack
- Re: Please don't flame me...why is there no "++" in Ruby again ?
- Prev by Date: Re: mechanize 0.7.8 Released
- Next by Date: [ANN] geoip 0.8.0 Released
- Previous by thread: [ANN] mechanize 0.7.8 Released
- Next by thread: Re: Please don't flame me...why is there no "++" in Ruby again ?
- Index(es):
Relevant Pages
|