Created
December 16, 2015 00:52
-
-
Save tompave/ee9649bfc375654fda5d to your computer and use it in GitHub Desktop.
closures in Ruby
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
i = 1000 | |
f1 = Proc.new { |x| x * x } | |
f2 = -> (func, int) { puts "the result is: '#{func.call(int)}', i is: '#{i}'" } | |
def run(range, operation, printer) | |
range.each do |i| | |
printer.call(operation, i) | |
end | |
end | |
run 1..4, f1, f2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment