Created
September 24, 2013 11:55
-
-
Save lukaszsagol/6683649 to your computer and use it in GitHub Desktop.
Lambdas in case expressions
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
def is(method_sym) | |
->(subject) { subject.send method_sym } | |
end | |
case user | |
when is(:admin) then puts 'Woohoo! Admin' | |
when is(:editor) then puts 'Editor' | |
else puts 'User' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment