A
Adam Akhtar
Hi after a bit of searching and reading im quite confused by this.
I first learnt C so used to being able to pass by reference or by value.
In Ruby its just by reference (so ive just found out after an hour of
chasing a bug).
I have an array of ojbects which are baisically acting like structures.
I want to pass the array to a function. This function will take the
array, make a new copy so as to protect the original from any changes.
Changes will be made to the copy and then the copy is returned.
How do i do that?
Ive looked dup but i dont think it works for objects... isnt there a
method to copy an object (i.e make new space in memory and put the data
there rather than juts pointing to the original objects address).
Id have thought it was necessary if you can only pass by reference...or
is the above considered bad design practice in ruby?
I first learnt C so used to being able to pass by reference or by value.
In Ruby its just by reference (so ive just found out after an hour of
chasing a bug).
I have an array of ojbects which are baisically acting like structures.
I want to pass the array to a function. This function will take the
array, make a new copy so as to protect the original from any changes.
Changes will be made to the copy and then the copy is returned.
How do i do that?
Ive looked dup but i dont think it works for objects... isnt there a
method to copy an object (i.e make new space in memory and put the data
there rather than juts pointing to the original objects address).
Id have thought it was necessary if you can only pass by reference...or
is the above considered bad design practice in ruby?