Created
June 7, 2018 17:19
-
-
Save tomholford/efd005d00bee66a30090278c25bcab5a to your computer and use it in GitHub Desktop.
even / odd classifier using proc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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