Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created February 15, 2010 16:30
Show Gist options
  • Save workmad3/304771 to your computer and use it in GitHub Desktop.
Save workmad3/304771 to your computer and use it in GitHub Desktop.
ruby-1.8.7-p248 > module Foo
ruby-1.8.7-p248 ?> def self.included(base)
ruby-1.8.7-p248 ?> def base.do_foo
ruby-1.8.7-p248 ?> Foo.send :define_method, :write do
ruby-1.8.7-p248 > puts "1"
ruby-1.8.7-p248 ?> end
ruby-1.8.7-p248 ?> end
ruby-1.8.7-p248 ?> end
ruby-1.8.7-p248 ?> end
=> nil
ruby-1.8.7-p248 > module Bar
ruby-1.8.7-p248 ?> def write
ruby-1.8.7-p248 ?> puts "2"
ruby-1.8.7-p248 ?> end
ruby-1.8.7-p248 ?> end
=> nil
ruby-1.8.7-p248 > class Thing
ruby-1.8.7-p248 ?> include Foo
ruby-1.8.7-p248 ?> do_foo
ruby-1.8.7-p248 ?> include Bar
ruby-1.8.7-p248 ?> end
=> Thing
ruby-1.8.7-p248 > Thing.new.write
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment