Skip to content

Instantly share code, notes, and snippets.

@MaxPleaner
Created March 17, 2017 06:21
Show Gist options
  • Save MaxPleaner/6b517a9c3ee4425651ef0f73ef14318b to your computer and use it in GitHub Desktop.
Save MaxPleaner/6b517a9c3ee4425651ef0f73ef14318b to your computer and use it in GitHub Desktop.
example of closure in ruby when redefining value of self
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