Created
August 24, 2019 14:07
-
-
Save lazyvar/e55af541b6b2ec16ce194daff7bf045a to your computer and use it in GitHub Desktop.
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
/** | |
Inspired by rails `StringInquirer` | |
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/string_inquirer.rb | |
**/ | |
@dynamicMemberLookup | |
struct StringInquirer { | |
let string: String | |
init(_ string: String) { self.string = string } | |
subscript(dynamicMember member: String) -> Bool { | |
return string == member | |
} | |
} | |
extension String { | |
var `is`: StringInquirer { | |
return StringInquirer(self) | |
} | |
} | |
"mack".is.mack // true | |
"mack".is.jack // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment