Skip to content

Instantly share code, notes, and snippets.

@alexandru-calinoiu
Last active September 29, 2016 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandru-calinoiu/bbee0d650adfd87db5a47f998ca0f7ee to your computer and use it in GitHub Desktop.
Save alexandru-calinoiu/bbee0d650adfd87db5a47f998ca0f7ee to your computer and use it in GitHub Desktop.
Playing with ruby case
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
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