文法修正アプリを作成しています。スラングを入力すると、正式な英語の修正が返されます。サポートされているすべての俗語は、配列内に保持されます。サポートされていないスラングが入力された場合に、このようなメソッドを作成しました。
def addtodic(lingo)
print"\nCorrection not supported. Please type a synonym to add '#{lingo}' the dictionary: "
syn = gets.chomp
if $hello.include?("#{syn}")
$hello.unshift(lingo)
puts"\nCorrection: Hello.\n"
elsif $howru.include?("#{syn}")
$howru.unshift(lingo)
puts"\nCorrection: Hello. How are you?\n"
end
end
これは機能しますが、アプリケーションが閉じられるまでのみです。ソースコードも修正するように、これを永続化するにはどうすればよいですか? それができない場合、すべてのケースを保持する外部ファイルを作成し、それをソース コードで参照するにはどうすればよいでしょうか?