LoginSignup
4
4

More than 5 years have passed since last update.

ズンドコキヨシマシーン with Ruby

Last updated at Posted at 2016-03-14

ズンドコキヨシマシーン

カウントアップする機械、ドコ命令はカウントが4未満ならリセットするが4以上になった場合、キヨシ命令を実行する

class ZunDokoMachine
  def initialize
    @counter = 0
  end

  def ズン
    puts __method__
    @counter += 1
  end

  def ドコ
    puts __method__

    if @counter < 4
      @counter = 0
    else
      キヨシ
    end
  end

  private

  def キヨシ
    puts __method__
    exit
  end
end

ZunDokoMachine.new.instance_eval { loop { send(self.class.public_instance_methods(false).sample) } }

実行例

    _╰╰,   /バショ % ~/tmp
  _/o ŏァ  / タイチョー% ヤバイ
∈ミ;ノ,ノ   \コマンド% ruby hikiyoshi.rb
ドコ
ズン
ズン
ドコ
ドコ
ズン
ドコ
ドコ
ドコ
ズン
ドコ
ドコ
ズン
ズン
ズン
ドコ
ズン
ズン
ズン
ズン
ドコ
キヨシ

その他のキヨシ

4
4
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4