Skip to content

Instantly share code, notes, and snippets.

@fj
Created January 21, 2014 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fj/8541477 to your computer and use it in GitHub Desktop.
Save fj/8541477 to your computer and use it in GitHub Desktop.
Hypothetical pattern-matching API in Ruby.
(1..100).match do |i|
pattern(i%3, i%5) {
match [0, 0], "FizzBuzz" # match i%3 == 0, i%5 == 0
match [0, _], "Fizz" # match i%3 == 0, i%5 == anything
match [_, 0], "Buzz" # match i%3 == anything, i%5 == 0
}
end
# => [nil, nil, "Fizz", nil, "Buzz", "Fizz", ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment