Skip to content

Instantly share code, notes, and snippets.

@hryk
Created August 3, 2010 00:52
Show Gist options
  • Save hryk/505605 to your computer and use it in GitHub Desktop.
Save hryk/505605 to your computer and use it in GitHub Desktop.
#!/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