Created
March 21, 2014 08:22
-
-
Save RichardJordan/9681913 to your computer and use it in GitHub Desktop.
Adds attr instantiation and .all method to a class
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
module Helpers | |
module All | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
def initialize(attributes = {}) | |
attributes.each do |key, value| | |
instance_variable_set("@#{key}", value) | |
end | |
self.class.all << self | |
end | |
module ClassMethods | |
def all | |
@all ||= [] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment