Skip to content

Instantly share code, notes, and snippets.

@RichardJordan
Created March 21, 2014 08:22
Show Gist options
  • Save RichardJordan/9681913 to your computer and use it in GitHub Desktop.
Save RichardJordan/9681913 to your computer and use it in GitHub Desktop.
Adds attr instantiation and .all method to a class
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