Skip to content

Instantly share code, notes, and snippets.

@marktabler
Created March 1, 2013 18:17
Show Gist options
  • Select an option

  • Save marktabler/5066619 to your computer and use it in GitHub Desktop.

Select an option

Save marktabler/5066619 to your computer and use it in GitHub Desktop.
Hipster Attr
class Class
def hipster_attr(*methods)
methods.each do |method|
define_method(method) do
instance_variable_get("@#{method}")
end
setter = method.to_s + "="
define_method(setter.to_sym) do |value|
instance_variable_set("@#{method}", value)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment