Skip to content

Instantly share code, notes, and snippets.

@yancya
Last active December 14, 2015 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yancya/5013572 to your computer and use it in GitHub Desktop.
Save yancya/5013572 to your computer and use it in GitHub Desktop.
万葉.rb の無限たこやきを表現してみた
# -*- 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