Created
June 10, 2015 21:42
-
-
Save qpfiffer/a6ccb303e17951563799 to your computer and use it in GitHub Desktop.
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
# Access elements of a dictionary or a class by string: | |
def get_var_ruby_style(var, x): | |
return x[var] if type(x).__name__ == 'dict' else getattr(x, var) | |
# Return a bound function that always accesses said element, like 'get_var_bound_ruby_style("added_at")' would | |
# always access the "added_at" value of whatever you pass in to it. Hooray closures! | |
def get_var_bound_ruby_style(var): | |
def bound_ruby_style(x): | |
return get_var_ruby_style(var, x) | |
return bound_ruby_style |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment