Skip to content

Instantly share code, notes, and snippets.

@tomholford
Created June 7, 2018 17:19
Show Gist options
  • Save tomholford/efd005d00bee66a30090278c25bcab5a to your computer and use it in GitHub Desktop.
Save tomholford/efd005d00bee66a30090278c25bcab5a to your computer and use it in GitHub Desktop.
even / odd classifier using proc
f = proc do |p|
Hash.new.merge(
->{ p.odd? }.call => 'odd',
->{ p.even? }.call => 'even'
).fetch(true)
end
=> #<Proc:0x00007ff91188af38@(irb):1>
> f[1]
=> "odd"
> f[2]
=> "even"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment