Created
April 26, 2016 13:35
-
-
Save joaquimadraz/f98cc022d707f9f44a1e5441e55f8349 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
# 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