Last active
August 29, 2015 13:56
-
-
Save jim80net/8870533 to your computer and use it in GitHub Desktop.
Class arbitrary instance attributes
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 method_missing(sym, *args) | |
name = sym.to_s | |
if name[-1,1] == '=' | |
instance_variable_set( "@#{name[0, name.size - 1]}", *args) | |
else | |
instance_variable_get("@#{name}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use in a class to allow for arbitrarily setting and getting instance variables.