Skip to content

Instantly share code, notes, and snippets.

@banister
Created March 12, 2012 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banister/45ee554408388e800b68 to your computer and use it in GitHub Desktop.
Save banister/45ee554408388e800b68 to your computer and use it in GitHub Desktop.
class Hello
def self.attr_accessor_with_history(*names)
names.each do |name|
attr_reader name
attr_reader "#{name}_with_history"
define_method("#{name}=") do |v|
if !instance_variable_defined?("@#{name}_with_history")
instance_variable_set("@#{name}_with_history", [])
end
instance_variable_get("@#{name}_with_history") << instance_variable_set("@#{name}", v)
end
end
end
end
# => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment