Feature #17834
Updated by Eregon (Benoit Daloze) over 3 years ago
"this is a string".bytes string.bytes should == Bytes.new('this is a string') # an immutable bytes object that implements memory view bytestring = Bytes.new('this is a string') mv = Fiddle::MemoryView.new(bytestring) mv[0] # 116 similary String.new('this is a string').bytes == ByteArray.new('this is a string') # a mutable byte array object that implements memoryview , takes an optional encoding that uses current string encoding ba = ByteArray.new('this is a string') mv = Fiddle::MemoryView.new(ba) mv[0] # 116 mv[0] = 120 # memoryview works on underlying object - changes mv.obj ba.pack('C*').force_encoding('UTF-8') # 'xhis is a string' also it would be good if String#bytes returns the new classes - (return something that implements memoryview)