Skip to content

Instantly share code, notes, and snippets.

@thisivan
Created December 14, 2009 19:13
Show Gist options
  • Save thisivan/256320 to your computer and use it in GitHub Desktop.
Save thisivan/256320 to your computer and use it in GitHub Desktop.
Create Attributes Accessor Dynamically in Ruby

Create Attributes Accessor Dynamically in Ruby

params.each do |key, value|
  self.instance_variable_set("@#{key}", value)
  self.class.send(:define_method, key, proc { self.instance_valiable_get("@#{key}") })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment