Created
August 17, 2011 06:52
-
-
Save rf-/1150973 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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