Skip to content

Instantly share code, notes, and snippets.

@cymen
Created April 27, 2012 01:43
Show Gist options
  • Save cymen/2504946 to your computer and use it in GitHub Desktop.
Save cymen/2504946 to your computer and use it in GitHub Desktop.
class Base
def self.hash_attr_accessor(*accessors)
accessors.each do |m|
define_method(m) do
@attributes[m]
end
define_method("#{m}=") do |value|
@attributes = {} if @attributes.nil?
@attributes[m] = value
end
end
end
def initialize(attributes = {})
attributes.each do |key, value|
send("#{key}=", value) if respond_to?("#{key}=")
end
end
def attributes
return @attributes.dup
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment