Created
November 13, 2011 16:33
-
-
Save nicholasjhenry/1362299 to your computer and use it in GitHub Desktop.
Recycle App with Module #railsisnotyourapp
This file contains hidden or 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
| # 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