increment/decrement

T

Teodor Carstea

what is Ruby's style of increment/decrement?

I mean like in C++

someVar++
or someVar--
 
P

Paul Smith

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)
 
B

Bertram Scharpf

Hi,

Am Freitag, 04. Dez 2009, 21:34:31 +0900 schrieb Paul Smith:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top