Created
March 19, 2014 13:58
-
-
Save cheeyeo/9642179 to your computer and use it in GitHub Desktop.
Ruby: calling included classes within parent module
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 Search | |
@children = [] | |
def self.included(base) | |
@children << base | |
end | |
def self.query(val) | |
@children.each do |child| | |
child.query(val) | |
end | |
end | |
end | |
class A | |
include Search | |
def self.query(val) | |
p "Calling query A - with #{val}" | |
end | |
end | |
class B | |
include Search | |
def self.query(val) | |
p "Caling query B - with #{val}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment