Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > increment/decrement

Reply
Thread Tools

increment/decrement

 
 
Teodor Carstea
Guest
Posts: n/a
 
      12-04-2009
what is Ruby's style of increment/decrement?

I mean like in C++

someVar++
or someVar--
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Paul Smith
Guest
Posts: n/a
 
      12-04-2009
On Fri, Dec 4, 2009 at 12:22 PM, Teodor Carstea <(E-Mail Removed)> 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 Smith
http://www.nomadicfun.co.uk

http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Mike Stok
Guest
Posts: n/a
 
      12-04-2009

On Dec 4, 2009, at 7:22 AM, Teodor Carstea wrote:

> what is Ruby's style of increment/decrement?
>=20
> I mean like in C++
>=20
> someVar++
> or someVar--


Take a look at http://ruby-doc.org/docs/Newcomers/ruby.html#operators =
which includes "To increment a number, simply write x +=3D 1T."

Hope this helps,

Mike

--=20

Mike Stok <(E-Mail Removed)>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.





 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      12-04-2009
2009/12/4 Mike Stok <(E-Mail Removed)>:
>
> On Dec 4, 2009, at 7:22 AM, Teodor Carstea wrote:
>
>> what is Ruby's style of increment/decrement?
>>
>> I mean like in C++
>>
>> someVar++
>> or someVar--

>
> Take a look at http://ruby-doc.org/docs/Newcomers/ruby.html#operators 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
???".

http://groups.google.de/group/comp.l...3161b23e9e57d1

Cheers

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

 
Reply With Quote
 
Bertram Scharpf
Guest
Posts: n/a
 
      12-04-2009
Hi,

Am Freitag, 04. Dez 2009, 21:34:31 +0900 schrieb Paul Smith:
> On Fri, Dec 4, 2009 at 12:22 PM, Teodor Carstea <(E-Mail Removed)> 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


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments