Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.