Copying means a new copy, right ?
Well I would think that is the reasonable thing to do, but ruby don't like this idea, to me this is a bug.
I would not make a new variable of something if I intended to change the original and the new one at the same time right ?
So to me this is a breaking bug.
I have this BitBoard that I would like to have be 0's and 1's, so I would like to take a copy and change that one to make it easier to make a board that shows the current position in a human readable format.
In ruby this is a lot harder than it should be, I am no genius programmer or anything so I know this will fuck me up later, I really dislike when I have to be extra careful, even when I thought I had taken care of it, I can really change the old one back if they are the same thing.
So if I do
in Ruby guess what a is after this operation.
even though I had done this with returning b, however a is still affected by this block.
This is terrible.
I am done with ruby I am not looking for a work-around, work-arounds are terrible.
So I am looking for a better language.
Remember to Upvote, Resteem and Follow
There are many languages where b = a will not create a copy of the object, but instead just point the variable a to the value held at object b. This is actually intended language behavior. It is the same in the language I use, smalltalk.
If you google "ruby copy" or "ruby deepcopy" you will find some pages with instructions on how to do a copy or deep copy in Ruby.
Yeah there is a work-around, but I am really not interested.
I would like if I could say
b=a
and get a new thing that is not just a referencethe weird thing happens when I change it at the top level, then a is unaffected, but when I copy inside a function or something like that a is also affected, if this is intended behavior I am out of that language.