Skip to content

Instantly share code, notes, and snippets.

@hryk
Created August 3, 2010 01:14
Show Gist options
  • Select an option

  • Save hryk/505646 to your computer and use it in GitHub Desktop.

Select an option

Save hryk/505646 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
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