Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Tuesday, March 1, 2011

Ruby ++ and --

This is the missing post from Aleksi Niemela explaining why Ruby hasn't got ++ and -- operators:

(1) ++ and -- are NOT reserved operator in Ruby. (2) C's increment/decrement operators are in fact hidden assignment. They affect variables, not objects. You cannot accomplish assignment via method. Ruby uses +=/-= operator instead. (3) self cannot be a target of assignment. In addition, altering the value of integer 1 might cause severe confusion throughout the program.


http://web.archive.org/web/20030901065005/www.ruby-talk.org/blade/2710

Coming from Perl, you've got to watch this: ++a silently does nothing (it's interpreted as two unary plus operators, +(+a) ) and a++ is an error.

Followers

Blog Archive