Skip to content

Instantly share code, notes, and snippets.

@charly
Created August 19, 2009 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charly/170482 to your computer and use it in GitHub Desktop.
Save charly/170482 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'facets'
module Creme
def cost
puts "before_filter"
super
end
end
class Coffee
prepend Creme
def cost
puts "3"
end
end
coffee = Coffee.new
coffee.cost
#But guess what, it's by overriding new:
# facet library
def prepend( aspect )
_new = method(:new)
_allocate = method(:allocate)
(class << self; self; end).class_eval do
define_method(:new) do |*args|
o = _new.call(*args)
o.extend aspect
o
end
define_method(:allocate) do |*args|
o = _allocate.call(*args)
o.extend aspect
o
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment