Skip to content

Instantly share code, notes, and snippets.

@brainopia
Created February 12, 2012 16:38
Show Gist options
  • Save brainopia/1809554 to your computer and use it in GitHub Desktop.
Save brainopia/1809554 to your computer and use it in GitHub Desktop.
class Fiber
yield_method = method(:yield)
resume_method = instance_method(:resume)
singleton_class.send(:define_method, :yield) do |*args|
puts "yield #{Fiber.current}"
yield_method.call *args
end
define_method(:resume) do |*args|
puts "resume #{self}"
resume_method.bind(self).call *args
end
def name=(value)
@name = value
end
def to_s
@name || super
end
end
f1.name = 'fiber 1'
f2.name = 'fiber 2'
f3.name = 'fiber 3'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment