Skip to content

Instantly share code, notes, and snippets.

@jeena
Created May 5, 2010 08:38
Show Gist options
  • Save jeena/390539 to your computer and use it in GitHub Desktop.
Save jeena/390539 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -wKU
module Kernel
alias λ proc
def ∑ *terms
terms.inject { |sum, term| sum + term }
end
def √ term
Math.sqrt term
end
end
def say_formula text, a, b, formula
puts "#{text}#{formula.call(a, b)}"
end
a, b = 2, 3
say_formula "Pythagoras says if a is #{a} and b is #{b} then c is ", a, b, λ {|a,b| √ a*a + b*b }
say_formula "I say if a is #{a} and b is #{b} then a + b = ", a, b, λ {|a,b| ∑ a, b }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment