Skip to content

Instantly share code, notes, and snippets.

@dv
Created September 8, 2011 00:02
Show Gist options
  • Save dv/1202222 to your computer and use it in GitHub Desktop.
Save dv/1202222 to your computer and use it in GitHub Desktop.
Put a Fiber around any method using as_fiber.
class Object
def as_fiber(*method_names)
method_names.each do |method_name|
alias_method "fiberless_#{method_name}", method_name
module_eval <<-eos
def #{method_name}(*args)
Fiber.new do
fiberless_#{method_name}(*args)
end.resume
end
eos
end
end
end
# Example use
class String
as_fiber :size
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment