Skip to content

Instantly share code, notes, and snippets.

@jim80net
Last active August 29, 2015 13:56
Show Gist options
  • Save jim80net/8870533 to your computer and use it in GitHub Desktop.
Save jim80net/8870533 to your computer and use it in GitHub Desktop.
Class arbitrary instance attributes
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
@jim80net
Copy link
Author

jim80net commented Feb 7, 2014

Use in a class to allow for arbitrarily setting and getting instance variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment