Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@844196

キヨシ

時期を逃してるし、短くも気持ち悪い書き方もできないはちよんは、疲れからか不幸にも黒塗りの高級車に追突してしまう…

kiyoshi.rb
module Kiyoshi
  class Phrase
    attr_accessor :words, :pattern, :finish

    def initialize
      yield(self)
    end

    def sing
      string = ''
      string << words.sample.tap(&:display) until string =~ pattern
      puts finish
    end
  end

  class << self
    def sing(&config)
      phrase = Phrase.new(&config)
      phrase.sing
    end
  end
end
app.rb
require_relative 'kiyoshi'

Kiyoshi.sing do |zundoko|
  zundoko.words   = %w(ズン ドコ)
  zundoko.pattern = /(?:ズン){4}ドコ/
  zundoko.finish  = 'キ・ヨ・シ!'
end

Kiyoshi.sing do |shintyoku|
  shintyoku.words   = %w(進捗 どう です か)
  shintyoku.pattern = /進捗どうですか/
  shintyoku.finish  = '?'
end

Kiyoshi.sing do |yajyu|
  yajyu.words   = %w(114 514 810 1919)
  yajyu.pattern = /1145148101919/
  yajyu.finish  = '胸にかけて胸に!'
end
$ ruby app.rb
ズンドコドコズンドコドコズンドコズンズンズンズンズンドコキ・ヨ・シ!
進捗進捗かかですか進捗か進捗進捗どう進捗かどう進捗かどうか進捗ですどうですどう進捗進捗どうどう進捗進捗進捗進捗ですどうどうですか進捗どうですか?
1919114114191911411481011481011451419191919191981081051419195145148108101145145145141145148101919胸にかけて胸に!
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
1
Help us understand the problem. What are the problem?