歌うズンドコキヨシ
気づき: キ・ヨ・シ!は歌詞ではなかった
Macのsayコマンドでズンドコ言います。
class RandomZundokoLyrics
ZUN_DOKO = ['ズン', 'ドコ']
include Enumerable
def each
loop do
yield ZUN_DOKO.sample
end
end
end
class Kiyoshi
def sing(lyrics)
lyrics.each do |word|
system 'say', word
yield word
end
end
end
class ZundokoKiyoshiFan
CHANT = 'キ・ヨ・シ!'
CHANT_TIMING_LYRICS = ['ズン', 'ズン', 'ズン', 'ズン', 'ドコ']
def initialize
@words_buffer = []
end
def <<(word)
@words_buffer << word
if @words_buffer.size > CHANT_TIMING_LYRICS.size
@words_buffer.shift
end
end
def chant_timing?
@words_buffer == CHANT_TIMING_LYRICS
end
def chant
system 'say', CHANT
end
end
def ズンドコ♪
kiyoshi = Kiyoshi.new
lyrics = RandomZundokoLyrics.new
fan = ZundokoKiyoshiFan.new
kiyoshi.sing(lyrics) do |word|
fan << word
fan.chant and exit if fan.chant_timing?
end
end
ズンドコ♪
実行例
(sayコマンドから音声が聞こえてくる)