what is Ruby’s style of increment/decrement?
I mean like in C++
someVar++
or someVar–
what is Ruby’s style of increment/decrement?
I mean like in C++
someVar++
or someVar–
On Fri, Dec 4, 2009 at 12:22 PM, Teodor C.
[email protected] wrote:
what is Ruby’s style of increment/decrement?
I mean like in C++
someVar++
or someVar–
someVar += 1
Or, more likely, work out why you don’t really need to increment and
use something else (hint, if you’re incrementing an array index,
you’re probably doing it wrong)
–
Posted via http://www.ruby-forum.com/.
–
Paul S.
http://www.nomadicfun.co.uk
On Dec 4, 2009, at 7:22 AM, Teodor C. wrote:
what is Ruby’s style of increment/decrement?
I mean like in C++
someVar++
or someVar–
Take a look at Ruby-Doc.org: Documenting the Ruby Language
which includes “To increment a number, simply write x += 1T.”
Hope this helps,
Mike
–
Mike S. [email protected]
http://www.stok.ca/~mike/
The “`Stok’ disclaimers” apply.
Hi,
Am Freitag, 04. Dez 2009, 21:34:31 +0900 schrieb Paul S.:
On Fri, Dec 4, 2009 at 12:22 PM, Teodor C. [email protected] wrote:
what is Ruby’s style of increment/decrement?
I mean like in C++
someVar++
or someVar–someVar += 1
You may also say
someVar = someVar.succ
With strings even this works:
str = “A0000”
str.succ!
For iterating use somethig like Fixnum#times or Array#each.
Bertram
2009/12/4 Mike S. [email protected]:
Take a look at Ruby-Doc.org: Documenting the Ruby Language which includes “To increment a number, simply write x += 1T.”
Teodor, if you now start wondering why there is no i++ in Ruby please
see the recent thread “Ruby doesn’t implement x++ for Fixnum’s because
???”.
Cheers
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs