Skip to content

Instantly share code, notes, and snippets.

@pritchie
Created May 24, 2013 21:55
Show Gist options
  • Save pritchie/5646765 to your computer and use it in GitHub Desktop.
Save pritchie/5646765 to your computer and use it in GitHub Desktop.
module AwesomeResource
attr_reader :awesome_attributes
def initialize(attributes={})
@awesome_attributes = attributes # AwesomeResource::Attributes.new attributes
define_attribute_accessors
end
private
def define_attribute_accessors
awesome_attributes.each_key do |k|
self.class.send(:define_method, k, Proc.new { @awesome_attributes[k] })
self.class.send(:define_method, "#{k}=", Proc.new { |v| @awesome_attributes[k] = v })
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment