Skip to content

Instantly share code, notes, and snippets.

@joalbertg
Created May 22, 2020 16:46
Show Gist options
  • Save joalbertg/6b15a95ccf02629e7696ff4874eb32ef to your computer and use it in GitHub Desktop.
Save joalbertg/6b15a95ccf02629e7696ff4874eb32ef to your computer and use it in GitHub Desktop.
ruby: Proc with case
# 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