Skip to content

Instantly share code, notes, and snippets.

@frsyuki
Last active January 7, 2016 00:24
Show Gist options
  • Save frsyuki/f93db28d446c3566f39e to your computer and use it in GitHub Desktop.
Save frsyuki/f93db28d446c3566f39e to your computer and use it in GitHub Desktop.
# re: http://twitter.com/kazuho/status/684889103796600832
def run_each(obj)
obj.each {|v| p v }
obj.close
end
def test
o = Struct.new(:is_open) do
def each(&block)
block.yield "hello\n"
end
def close
self.is_open = false
end
end.new
run_each(o)
if o.is_open
raise "close is not called!"
end
end
test
# re: http://twitter.com/kazuho/status/684889103796600832
def run_each(obj)
obj.each {|v| p v }
obj.close
end
def test
o = Class.new do
def initialize
@is_open = false
end
attr_reader :is_open
def each(&block)
block.yield "hello\n"
end
def close
@is_open = false
end
end.new
run_each(o)
if o.is_open
raise "close is not called!"
end
end
test
# re: http://twitter.com/kazuho/status/684889103796600832
def run_each(obj)
obj.each {|v| p v }
obj.close
end
def test
is_open = true
c = Class.new do
define_method(:each) {|&block| block.yield "hello\n" }
define_method(:close) { is_open = false }
end
run_each(c.new)
if is_open
raise "close is not called!"
end
end
test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment