I have a word "cap", and I want to create a new word that is exactly the same, but different final characters . The word "word # word" is "temporarily # # {temporary}", which is called "temporary" # {# temporarily} "
word =" hat "temp = word temp [temp.length-1] =" d " # Output: # temporary had # words
Now I had the temporary = "was"
and word = "hat"
but both The words have to be changed!
I have a hump that can be with both variables pointing to one place in memory?
Why is this happening, And how can I keep both values?
How can I keep it?
Use dup
this object
word = "cap "Temp = word.dup temp [temp.length-1] =" d "puts" temporary # # temporary} "," word # {word} "# output: # temporary word is #hat
< / Pre>
No comments:
Post a Comment