#!/usr/koeki/bin/ruby $KCODE = 'e' vocab = Hash.new STDERR.printf("何か教えてよ\n") sentence = gets.chomp while true if /^(\S+)(は)(\S+)(ね|の|だ|で)/ =~ sentence # p sentence topic = $1 keyword = $3 end vocab[keyword] = topic # vocab[topic] = keyword # p vocab vocab.each{ |check| if (vocab.value?(topic) == true && check[0] != keyword) printf("%sっていうのは%sだね\n",check[0],keyword) print("他にも教えてよ\n") break else printf("%sってなあに?\n",check[1]) break end } sentence = gets.chomp end