class C
@a = StaticArray(UInt8, 4).new 0
def b
b = @a.to_slice
b[1] = 1_u8
c = @a
c.to_slice
c[2] = 2_u8
end
end
c = C.new
c.b
p c
The second modification doesn’t modify the original StaticArray.
Output:
#<C:0x10c19eff0 @a=StaticArray[0, 1, 0, 0]>