Created
April 26, 2016 16:21
-
-
Save gwmoura/33a9216bfb728f6b391c7e4b336684e6 to your computer and use it in GitHub Desktop.
Simple Gist to create a Module with class methods
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 Plan | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def components_methods(components) | |
components.each do |key, value| | |
attr_accessor(key) | |
end | |
end | |
end | |
end | |
class MyPlan | |
include Plan | |
components_methods %w(disk memory cpu) | |
end | |
plan = MyPlan.new | |
puts plan.disk | |
plan.disk='Disk0' | |
puts plan.disk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been thinking about
mixing
andinheritance
and I think (think because I haven't tried to change the codebase yet) that inheritance will be good on this rails because of STI, STI helps us a LOT... and to haveMyPlan
mapped to a database that we need STIAfter refactoring prices I'm gonna be able to do some tests on this
the idea of this gist (think on OO is cool), but I don't know if using Rails and AR STI would save us a lot of work