Created
September 14, 2014 07:10
-
-
Save ttanimichi/874ababfd2454b167f74 to your computer and use it in GitHub Desktop.
prependされたときにクラスメソッドとインスタンスメソッドを同時に追加するパターン
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
module M | |
def self.prepended(base) | |
class << base | |
self.prepend(ClassMethods) | |
end | |
end | |
module ClassMethods | |
def c | |
puts 'c' | |
end | |
end | |
def a | |
puts 'a' | |
end | |
end | |
class C | |
prepend M | |
def b | |
puts 'b' | |
end | |
end | |
C.new.b | |
C.new.a | |
C.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment