Created
November 21, 2011 19:28
-
-
Save ngauthier/1383631 to your computer and use it in GitHub Desktop.
currying an instance method
This file contains hidden or 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
class Foo | |
def foo(x) | |
"foo! #{x}" | |
end | |
def bar | |
# my imaginary syntax for "create functional reference from method foo with argument bar. | |
&(:foo, 5) | |
end | |
end | |
# Foo.new.bar.call | |
# => "foo! 5" |
ah yeah I thought lambda's didn't keep scope, but they do. Is it procs that don't keep scope? Or you you have to manually bind
to change scope?
Thanks.
closures always keep their scope?! but you can "ignore" their original binding and evaluate them in a different context if you like.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just return a lambda?