-
-
Save kennethkalmer/fcc470851d9556321ab0 to your computer and use it in GitHub Desktop.
Module magic with extend self, and extending others
This file contains 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
irb(main):001:0> Bar.bar | |
=> :barred | |
irb(main):002:0> Bar.new.bar | |
=> :barred | |
irb(main):003:0> Foo.bar | |
=> :barred |
This file contains 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
module Foo | |
extend self | |
def self.included(base) | |
base.extend(self) | |
end | |
def bar | |
:barred | |
end | |
end | |
class Bar | |
include Foo | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment