入力内容を確認して、単語を Ruby の 300 対の反意語に置き換えたいと考えています。
Python では、辞書を作成するのが効率的な方法ですreplace
。
Ruby でgsub!
行ごとに使用すると、ハッシュを使用するよりもはるかに効率が悪くなりますか? 300足しか持っていなくても違いはありますか?
body=ARGV.dup
body.gsub!("you ","he ")
body.gsub!("up","down ")
body.gsub!("in ","out ")
body.gsub!("like ","hate ")
body.gsub!("many ","few ")
body.gsub!("good ","awesome ")
body.gsub!("all ","none ")