Skip to content

Instantly share code, notes, and snippets.

@nicholasjhenry
Created November 13, 2011 16:33
Show Gist options
  • Select an option

  • Save nicholasjhenry/1362299 to your computer and use it in GitHub Desktop.

Select an option

Save nicholasjhenry/1362299 to your computer and use it in GitHub Desktop.
Recycle App with Module #railsisnotyourapp
# RecycleApp
module RecycleApp
class << self
attr_accessor :can_store
def config
yield self
end
end
end
module RecycleApp::Can
attr_reader :amount
def initialize
@amount = 0
end
def incr
@amount += 1
end
end
# Rails App
RecycleApp.config do |config|
can_store = CanStore.new
end
class CanStore
def new
Can.new
end
end
class Can < ActiveRecord
include RecycleApp::Can
def incr
super
save!
end
end
# Usage
c = RecycleApp.can_store.new
c.incr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment