Created
August 3, 2010 01:14
-
-
Save hryk/505646 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 | |
| class << self | |
| alias_method :monjayaki_without_modern, :monjayaki | |
| def monjayaki(man) | |
| self.class_eval 'def '+ man + | |
| '; puts " and ' + | |
| man + ' ate modern yaki" ; end' | |
| 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