samedi 27 juin 2015

How to create a Ruby array slice which shares the same instance of the original array?

So that if the slice gets changed, the original array will also change?

a = [1, 2, 3]
b = a[1, 2]
b[0] = 42 # due to COW, only b changes, a remains unchanged

Expected result: when run b[0] = 42, a[1] will also changed to 42.

Aucun commentaire:

Enregistrer un commentaire