-
-
Save koraktor/1092043 to your computer and use it in GitHub Desktop.
Method Missing Demo
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 MyModule | |
# Defines method_missing | |
module ClassMethods | |
def method_missing(method) | |
puts "Method: \"#{method}\" does not exist." | |
end | |
end | |
# Will add method_missing to MyModule itself | |
extend ClassMethods | |
# Will add method_missing to all modules/classes that include MyModule | |
def self.included(mod) | |
mod.extend ClassMethods | |
end | |
# Public methods..... | |
def self.doSomething(parameter) | |
... | |
end | |
def self.doSomethingElse() | |
... | |
end | |
end | |
# EOF | |
I want the following, as demonstrated in IRB: | |
> require "mymodule" | |
=> true | |
> MyModule.doSomething() | |
=> (output) | |
> MyModule.doesNotExist() | |
=> Method: "doesNotExist" does not exist. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment