Skip to content

Instantly share code, notes, and snippets.

@neilmiddleton
Created May 11, 2011 10:34
Show Gist options
  • Save neilmiddleton/966257 to your computer and use it in GitHub Desktop.
Save neilmiddleton/966257 to your computer and use it in GitHub Desktop.
Create class from hash
def initialize(hash)
hash.each do |k,v|
self.instance_variable_set("@#{k.underscore}", v)
self.class.send(:define_method, k.underscore, proc{self.instance_variable_get("@#{k.underscore}")})
self.class.send(:define_method, "#{k.underscore}=", proc{|v| self.instance_variable_set("@#{k.underscore}", v)})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment