Skip to content

Instantly share code, notes, and snippets.

@jleeothon
Created April 19, 2015 23:59
Show Gist options
  • Save jleeothon/a06bf5367c575baad000 to your computer and use it in GitHub Desktop.
Save jleeothon/a06bf5367c575baad000 to your computer and use it in GitHub Desktop.
Ruby dynamically resolve names from a hash
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