On one pc i am getting this on ruby 1.8.6 and on other pc i am getting error
irb(main):001:0> buff = "12345678"
=> "12345678"
irb(main):002:0> buff[4] =0x30
=> 48
irb(main):003:0> buff
=> "12340678"
irb(main):004:0> @new0 = "123456789"
=> "123456789"
irb(main):005:0> @new0[4] = 0x30
=> 48
> @buff ="123456789"
=> "123456789"
> @buff
=> "123456789"
> @buff[4]= 0x30
TypeError: can't convert Fixnum into String
from (irb):3:in `[]='
from (irb):3
> @buff[4] = 0x30
Seems like you are using Ruby 1.9 in your second example. The
[]=method has changed and only accepts strings.You can convert an integer value to a string using
chr:And retrieve a character’s byte value with: