Created
August 3, 2010 00:57
-
-
Save hryk/505615 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'extlib' | |
#################################################### | |
module Baz | |
module Extension | |
class << self | |
def included(base) | |
base.send :extend , Base | |
end | |
end | |
module Base | |
def monjayaki(man) | |
class_eval <<-EOS | |
def #{man} | |
puts "#{man} ate monjayaki with " + @name | |
end | |
EOS | |
end | |
end | |
end | |
end | |
#################################################### | |
module Bar | |
class << self | |
def included(base) | |
base.class_eval <<-EOF | |
include Baz::Extension | |
include Extlib::Hook | |
before_class_method(:monjayaki) { puts "before monjayaki, they ate modern yaki. " } | |
# alias_method :modern_yaki, :monjayaki | |
# def monjayaki(name) | |
# class_eval "def "+name+' ; puts " ' + name + 'ate modern_yaki with ' + @name + '"; end' | |
# end | |
EOF | |
end | |
end | |
end | |
#################################################### | |
class Foo | |
include Bar | |
def initialize(name) | |
@name = name | |
end | |
def greet(greet="") | |
puts "#{greet} #{@name} " | |
end | |
monjayaki('mike') | |
end | |
foo = Foo.new("john") | |
foo.greet("hello!") | |
foo.mike | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment