Skip to content

Instantly share code, notes, and snippets.

@hosiawak
Created June 29, 2011 09:31
Show Gist options
  • Save hosiawak/1053518 to your computer and use it in GitHub Desktop.
Save hosiawak/1053518 to your computer and use it in GitHub Desktop.
def before(method_sym, &block)
old_method = self.instance_method(method_sym)
if old_method.arity == 0
define_method(method_sym) do
block.call
old_method.bind(self).call
end
else
define_method(method_sym) do |*params|
old_method.bind(self).call(*block.call(*params))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment