Created
May 22, 2020 16:46
-
-
Save joalbertg/6b15a95ccf02629e7696ff4874eb32ef to your computer and use it in GitHub Desktop.
ruby: Proc with case
This file contains hidden or 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
# https://womanonrails.com/functional-programming-ruby | |
proc1 = Proc.new { |number| number % 3 == 0 } | |
proc2 = Proc.new { |number| number % 3 == 1 } | |
case 3 | |
when proc1 then p 'proc1' | |
when proc2 then p 'proc2' | |
else | |
p 'not a proc' | |
end | |
"proc1" | |
=> "proc1" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment