Created
August 3, 2010 00:52
-
-
Save hryk/505605 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 | |
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 Baz::Extension | |
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.test | |
foo.mike | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment