Skip to content

Instantly share code, notes, and snippets.

@gwmoura
Created April 26, 2016 16:21
Show Gist options
  • Save gwmoura/33a9216bfb728f6b391c7e4b336684e6 to your computer and use it in GitHub Desktop.
Save gwmoura/33a9216bfb728f6b391c7e4b336684e6 to your computer and use it in GitHub Desktop.
Simple Gist to create a Module with class methods
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
@fernandes
Copy link

I've been thinking about mixing and inheritance 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 have MyPlan mapped to a database that we need STI

After 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment