Created
July 27, 2012 08:34
-
-
Save inre/3186847 to your computer and use it in GitHub Desktop.
get class module
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
require 'rails' | |
module OtherModule | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def module | |
("::"+self.to_s.split("::").tap {|m| m.pop }.join('::')).constantize | |
end | |
def foo | |
puts "I know your module #{self.module}" | |
end | |
end | |
end | |
module ModuleName | |
module SubModule | |
class MyClass | |
include OtherModule | |
end | |
end | |
end |
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
1.9.3-p0 :079 > ModuleName::SubModule::MyClass.foo | |
I know your module ModuleName::SubModule | |
=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment