Skip to content

Instantly share code, notes, and snippets.

@jyunderwood
Last active August 29, 2015 13:56
Show Gist options
  • Save jyunderwood/9234575 to your computer and use it in GitHub Desktop.
Save jyunderwood/9234575 to your computer and use it in GitHub Desktop.
##
# Will keep all passed in attributes in the `attributes` attribute
# But will allow you to pull out certain attributes that you want as
# getters and setters. Great for accessing with `random_object.some`
#
class RandomObject
WANTED_ATTRS = [:some, :attrs, :you, :want]
attr_accessor :attributes, *WANTED_ATTRS
def self.all(opts)
search_results = ExternalAPI::RandomObject.all(opts)
search_results.map! do |random_object|
self.new(random_object)
end
search_results
end
def initialize(attrs)
self.attributes = attrs
attrs.each { |key, val| send("#{key}=", val) if WANTED_ATTRS.include?(key) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment