Hashのeachで引き出される値の順番は一定ではない(ぽい)
半角カナを全角カナに変換したくて以下のような書き方してたけど、どうやらよくないっぽい
@texts = [["1", "アイウエオ"], ["2", "カキクケコ"], ["3", "サシスセソ"], ["4", "タチツテト"]] i = 0 @result = Hash.new @texts.each do |hoge| @result[i] = NKF.nkf("-wW", hoge[1]) i = i + 1 end
以下の書き方にすると直った
@texts = [["1", "アイウエオ"], ["2", "カキクケコ"], ["3", "サシスセソ"], ["4", "タチツテト"]] @result = Hash.new @texts.each_with_index do |hoge, index| @result[index] = NKF.nkf("-wW", hoge[1]) end
これで大丈夫かなぁ