Last active
August 29, 2015 14:14
-
-
Save Kameshwaran/ad3751971530dae69416 to your computer and use it in GitHub Desktop.
A simple string matcher in Ruby
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
class String | |
def method_missing(method, *args, &block) | |
method_name = method.to_s | |
if method_name.include?("is_") && method_name.include?("?") | |
method_name = method_name.gsub("is_", "")[0..-2] | |
(method_name == self) || (method_name.camelize == self) || (method_name.titleize == self) || (method_name.gsub(" ", "") == self) | |
else | |
super(method, *args, &block) | |
end | |
end | |
end | |
# "kamesh waran".is_kamesh_waran? # returns true | |
# "kamesh_waran".is_kamesh_waran? # returns true | |
# "Kamesh Waran".is_kamesh_waran? # returns true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment