You can not:
"\x0" += 1
Because in Ruby, this is short for:
"\x0" = "\x0" + 1
and this is a syntax error for assigning a value to a string literal.
However, given the integer n , you can convert it to a character using pack . For instance,
[97].pack 'U'
Similarly, you can convert a character to an integer using ord . For instance:
[300].pack('U').ord # => 300
Using these methods, you can easily write your own zoom function, as follows:
def step(c, delta=1) [c.ord + delta].pack 'U' end def increment(c) step c, 1 end def decrement(c) step c, -1 end
If you just want to manipulate bytes, you can use String # bytes , which will give you an array of integers to play back. You can use Array # pack to convert these bytes to a string. (Refer to the documentation for encoding parameters.)
source share