Skip to content

Instantly share code, notes, and snippets.

@joaquimadraz
Created April 26, 2016 13:35
Show Gist options
  • Save joaquimadraz/f98cc022d707f9f44a1e5441e55f8349 to your computer and use it in GitHub Desktop.
Save joaquimadraz/f98cc022d707f9f44a1e5441e55f8349 to your computer and use it in GitHub Desktop.
# source: http://blacklane.github.io/2016/04/23/lessons-learned-from-some-of-the-best-ruby-codebases-part-1/
class Foo < Module
def initialize
@module = Module.new
end
def included(descendant)
@module.class_eval do
def b
"B"
end
end
descendant.send(:include, @module)
end
end
# class Bar
# include Foo
# end
# TypeError: wrong argument type Class (expected Module)
# from (pry):2:in `include'
# [3] pry(main)> Foo.class
# => Class
class Bar
include Foo.new
end
puts Bar.new.b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment