Last active
August 29, 2015 13:56
-
-
Save jyunderwood/9234575 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# 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