1.在使用ruby的命令行参数的时候, 实际上是引用的赋值方式
测试代码, 保存为test.rb:
arg = ARGV[ 0 ]
arg.gsub!( /\r\n?/, "\n" )
运行test.rb会报错:
ruby test.rb string_to_test
test.rb:3:in `gsub!': can't modify frozen string (RuntimeError)
from test.rb:3:in `<main>'
有点不是太明白, ruby为什么要这样做
2.解决方法
arg = ARGV[ 0 ].dup
arg.gsub!( /\r\n?/, "\n" )
参考: http://stackoverflow.com/questions/2204945/ruby-cant-modify-frozen-string-typeerror