Re: Please don't flame me...why is there no "++" in Ruby again ?



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.

.



Relevant Pages

  • Re: Grep Guru
    ... On Mon, 9 Jun 2008, Giorgos Keramidas wrote: ... There's no more need for find | xargs ... -exec foo \+ behaves like xargs foo ...
    (freebsd-questions)
  • Re: Grep Guru
    ... There's no more need for find | xargs ... -exec foo \+ behaves like xargs foo ... -exec foo \; ...
    (freebsd-questions)
  • Re: Grep Guru
    ... -exec foo \+ behaves like xargs foo ... -exec foo \; ...
    (freebsd-questions)
  • Re: Dynamic stuff and books
    ... whether it's implemented in Ruby or C: ... def foo ... And so I think I found a really important use for singleton methods, ...
    (comp.lang.ruby)
  • Re: Why not Python? (No, no, I am not a spy)
    ... > ineteresting things about Ruby nowadays. ... Ruby (and Python) has a intellectual community. ... def foo: ... bar = foo # assigns the foo function to bar ...
    (comp.lang.ruby)