Created
March 20, 2013 20:44
-
-
Save ethagnawl/5208253 to your computer and use it in GitHub Desktop.
DSL for querying nth_letter of string.
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
def self.method_missing(method, *args) | |
number_dictionary = { | |
first: 1, | |
second: 2, | |
third: 3, | |
fourth: 4, | |
fifth: 5, | |
sixth: 6, | |
seventh: 7, | |
eigth: 8, | |
ninth: 9, | |
tenth: 10 | |
} | |
if method.to_s =~ /(.+)_letter/ && number = number_dictionary[$1.to_sym] | |
args[0][number - 1] | |
else | |
super | |
end | |
end | |
first_letter('hey') # h | |
second_letter('hey') # e | |
third_letter('hey') # y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment