Created
October 1, 2012 13:34
-
-
Save reconbot/3811831 to your computer and use it in GitHub Desktop.
Module Methods via Reflection
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 Routes | |
def home | |
#stuff | |
end | |
def work | |
#end | |
end | |
end | |
Routes.method_defined? :home | |
# true | |
Routes.send(:home) | |
#NoMethodError: undefined method `home' for Routes:Module |
I did want that, I ended up using Routes.respond_to?
instead of the include?
and now I know the difference between the module methods and instance methods in modules.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
method_defined? tells you if the module defines the instance method (for mixing in): http://www.ruby-doc.org/core-1.9.3/Module.html#method-i-method_defined-3F
maybe you wanted: