Forked from tinogomes/sugar syntax on Symbol object to verify if some symbol is equivalent to question
Created
December 8, 2011 15:51
-
-
Save lucascaton/1447386 to your computer and use it in GitHub Desktop.
symbol.rb
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
# You can check if current symbol is equivalent the question string | |
# | |
# e.g.: | |
# :symbol.symbol? # => true | |
# :symbol1.symbol1? # => true | |
# :sym_bol.sym_bol? # => true | |
# :"sym-bol".sym_bol? # => true | |
# :"sym bol".sym_bol? # => true | |
class Symbol | |
def method_missing(meth, *args, &blk) | |
if meth.to_s =~ /^(\S+)\?$/ | |
$1 == self.to_s.gsub(/(-|\s)/, "_") | |
else | |
super(meth, args, &blk) | |
end | |
end | |
end | |
# To test | |
if __FILE__ == $0 | |
gender = :male | |
gender.male? # result: true | |
gender.felame? # result: false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment