Created
May 3, 2012 05:50
-
-
Save slant/2583612 to your computer and use it in GitHub Desktop.
A file to demonstrate the difference between extending with ActiveSupport::Concern and without
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
| require 'rubygems' | |
| require 'active_support' | |
| module Stuff | |
| # New hotness | |
| extend ActiveSupport::Concern | |
| def whatnot | |
| 6 | |
| end | |
| # Old and busted | |
| # def self.included(base) | |
| # base.send :include, InstanceMethods | |
| # base.send :extend, ClassMethods | |
| # end | |
| # | |
| # module InstanceMethods | |
| # def whatnot | |
| # 6 | |
| # end | |
| # end | |
| module ClassMethods | |
| def whatnot | |
| 42 | |
| end | |
| end | |
| end | |
| class Thing | |
| include Stuff | |
| end | |
| puts Thing.new.whatnot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment