Created
April 19, 2015 23:59
-
-
Save jleeothon/a06bf5367c575baad000 to your computer and use it in GitHub Desktop.
Ruby dynamically resolve names from a hash
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 respond_to? method_sym, include_private = false | |
if @a.has_key? method_sym | |
true | |
else | |
super method_sym, include_private | |
end | |
end | |
def method_missing method_sym, *arguments, &block | |
if @a.has_key? method_sym | |
@a[method_sym] | |
else | |
super method_sym, *arguments, &block | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment