IRB と Ruby の式の実行方法に違いはありますか?
これらの式は、IRB とコマンド ラインから実行した場合に異なる結果をもたらします。問題は、どちらが正しいかです。
IRB:
>> s = 'hello'
=> "hello"
>> s.size
>> s[s.length] = '!'
IndexError: index 5 out of string
from (irb):31:in `[]='
from (irb):31
>>
通常のスクリプトでは、次のようになります。
s = 'hello'
s[s.length] = '!'
puts s
laptop user$ ./prgruby.rb
hello!