Skip to content

Instantly share code, notes, and snippets.

@ak47
Created June 6, 2012 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ak47/2883781 to your computer and use it in GitHub Desktop.
Save ak47/2883781 to your computer and use it in GitHub Desktop.
module B
def self.included(base)
class << base
attr_accessor :catch
def acts_as_catchall(hsh)
@catch = hsh
end
def inherited(subclass)
subclass.catch = subclass.superclass.catch
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
class D < C; end
p A.new.cat
p C.new.cat
p D.new.cat
class X
include B
acts_as_catchall :dog => 'ribbit'
end
class Y < X; end
p X.new.dog
p Y.new.dog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment