Skip to content

Instantly share code, notes, and snippets.

@tompave
Created December 16, 2015 00:52
Show Gist options
  • Save tompave/ee9649bfc375654fda5d to your computer and use it in GitHub Desktop.
Save tompave/ee9649bfc375654fda5d to your computer and use it in GitHub Desktop.
closures in Ruby
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