Skip to content

Instantly share code, notes, and snippets.

@rf-
Created August 17, 2011 06:52
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 rf-/1150973 to your computer and use it in GitHub Desktop.
Save rf-/1150973 to your computer and use it in GitHub Desktop.
module PartiallyApplicable
def apply_partially(new_name, old_name, *fixed_args)
define_method(new_name) do |*args|
self.send(old_name, *(fixed_args + args))
end
end
end
class MyClass
extend PartiallyApplicable
def plus(x, y)
x + y
end
apply_partially :plus1, :plus, 1
end
raise unless MyClass.new.plus(1, 2) == MyClass.new.plus1(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment