Created
November 14, 2012 01:05
-
-
Save ilake/4069539 to your computer and use it in GitHub Desktop.
LEVEL 5: MODULES
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
| Image.ancestors # [Image, ImageUtils, Object, Kernel, BasicObject] | |
| Image.included_modules # [ImageUtils, Kernel] | |
| class Image | |
| image = Image.new | |
| image.extend(ImageUtils) | |
| image.preview # an object is extending the module | |
| end | |
| # the module will not be available in other objects | |
| image = Image.new | |
| image.preview # NoMethodError: undefined method `preview' for #<Image:0x10b448a98> | |
|  | |
| module ImageUtils | |
| def self.included(base) | |
| base.extend(ClassMethods) | |
| base.clean_up | |
| end | |
| module ClassMethods | |
| def fetch_from_twitter(user) | |
| end | |
| def clean_up | |
| end | |
| end | |
| end | |
| require 'active_support/concern' | |
| module ImageUtils | |
| extend ActiveSupport::Concern | |
| included do | |
| clean_up | |
| end | |
| module ClassMethods | |
| def fetch_from_twitter(user) | |
| end | |
| def clean_up | |
| end | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment