Created
March 17, 2017 06:21
-
-
Save MaxPleaner/6b517a9c3ee4425651ef0f73ef14318b to your computer and use it in GitHub Desktop.
example of closure in ruby when redefining value of self
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
def proc_with_closure(val) | |
Proc.new { other_function(val) } | |
end | |
class Tester | |
def self.other_function(val) | |
val * 2 | |
end | |
end | |
Tester.class_eval &(proc_with_closure 1) | |
# => 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment