Last active
September 29, 2016 14:17
-
-
Save alexandru-calinoiu/bbee0d650adfd87db5a47f998ca0f7ee to your computer and use it in GitHub Desktop.
Playing with ruby 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
class Success | |
def self.===(item) | |
item.status >= 200 && item.status < 300 | |
end | |
end | |
class Empty | |
def self.===(item) | |
item.response_size == 0 | |
end | |
end | |
case http_response | |
when Enmpty | |
puts 'hurray' | |
when Success | |
puts 'boo!' | |
end | |
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
case 40 | |
when -> (n) { n.to_s == '40' } | |
puts 'evaluates lambda' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment