Created
June 6, 2012 04:03
-
-
Save 58bits/2879853 to your computer and use it in GitHub Desktop.
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 B | |
@@catch | |
def self.included(base) | |
class << base | |
def catch=(hsh) | |
@@catch = hsh | |
end | |
def catch | |
@@catch | |
end | |
def acts_as_catchall(hsh) | |
self.catch = hsh | |
end | |
end | |
end | |
def method_missing(meth, *args) | |
if s = self.class.catch[meth] | |
return s | |
else | |
super | |
end | |
end | |
end | |
class A | |
include B | |
acts_as_catchall :cat => 'meow' | |
end | |
class C < A | |
end | |
a = C.new | |
p a.cat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment