Skip to content

Instantly share code, notes, and snippets.

@britishtea
britishtea / example.rb
Last active December 31, 2015 16:09
Simple pattern matching in Ruby that won't win any beauty contests.
View example.rb
require 'function'
# A fibonacci function.
fib = Function.new
fib[0] = 0
fib[1] = 1
fib[Integer] = ->(i) { fib[i - 2] + fib[i - 1] }
p fib[0] # => 0