Xavier Noria wrote:
>    irb(main):003:0> "0011".tr("01", "10")
>    => "1100"

Or, if you're working with integers (as opposed to strings), then you 
can use the bitwise negation operator (~) and avoid the overhead of 
string conversions altogether:

  >> 0b1010
  => 10
  >> ~0b1010
  => -11
  >> ~(~0b1010)
  => 10
-- 
Posted via http://www.ruby-forum.com/.