Last active
December 14, 2015 02:28
-
-
Save yancya/5013572 to your computer and use it in GitHub Desktop.
万葉.rb の無限たこやきを表現してみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Ruby >= 2.0.0 | |
class Rubyist | |
def initialize | |
@ibukuro = Ibukuro.new | |
end | |
def mgmg(takoyaki) | |
begin | |
@ibukuro.push takoyaki | |
rescue IbukuroOverFlow | |
raise $! | |
ensure | |
puts "おいしい!" | |
end | |
end | |
def ganbaru | |
puts "まだいけます!!" | |
@ibukuro.clear | |
end | |
end | |
class Ibukuro < Array | |
def initialize | |
@limit = rand 50 | |
end | |
def push(obj) | |
super | |
if self.size > @limit | |
raise IbukuroOverFlow.new | |
end | |
end | |
end | |
class Takoyaki; end | |
class IbukuroOverFlow < Exception; end | |
infinity_takoyaki = (1..Float::INFINITY).lazy.map{Takoyaki.new} | |
rubyist = Rubyist.new | |
infinity_takoyaki.each do |takoyaki| | |
begin | |
rubyist.mgmg takoyaki | |
rescue IbukuroOverFlow | |
rubyist.ganbaru | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment