tags:

views:

343

answers:

2

Got

... '[]=': can't modify frozen string (TypeError)

when trying to modify what I thought was a copy of ARGV[0].

Same results for each of

arg = ARGV[ 0 ]
arg_cloned = ARGV[ 0 ].clone
arg_to_s = ARGV[ 0 ].to_s

arg[ 'x' ] = 'y'
arg_cloned[ 'x' ] = 'y'
arg_to_s[ 'x' ] = 'y'
+1  A: 

since google took too long to find the right answer ...

needed to do

arg_dup = ARGV[ 0 ].dup
Straff
Right. Clone copies the object's entire state, including frozen status. Dup copies the meat of the object without those other flags.
Eli
quite surprised that .to_s does the same (including frozen)!?
Straff
A: 

ok, why is ARGV frozen?

Jose
since it is variable that represents command-line arguments it makes sense not to be able to change them - changing a copy of them is fair but not the original
Straff