覚えた言葉を言わせてみる

Last-modified: 2018-05-04 (金) 11:48:19
 

せっかく言葉を覚えさせたので、その言葉を言わせてみます。

 

sittakaburi.rb

 require "yaml"
 class Sittakaburi
   def initialize
     begin
       @dictionary=YAML.load_file"dictionary.yaml"
     rescue
       puts "嫁>言葉を教えてあげようと思ったのだけれど、私の知っている言葉はただひとつ「AIしている?」だけ。"
       exit
     end
     ## ハッシュのキーを配列として取り出す。
     @wordslist=@dictionary.keys
   end
   def teach
     @word=@wordslist[rand(@wordslist.size)]
     puts "嫁>ねえ、「"+@word+"」の意味知ってる?"
     puts "嫁>それは「"+@dictionary[@word]+"」という意味なのよ。私って物知りでしょ?"
   end
 end
 sittakaburi=Sittakaburi.new
 sittakaburi.teach