Skip to content

Instantly share code, notes, and snippets.

@ilake
Created November 14, 2012 01:05
Show Gist options
  • Select an option

  • Save ilake/4069539 to your computer and use it in GitHub Desktop.

Select an option

Save ilake/4069539 to your computer and use it in GitHub Desktop.
LEVEL 5: MODULES
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