Skip to content

Instantly share code, notes, and snippets.

@iwadon
Forked from anonymous/gist:12221
Created September 28, 2008 08:07
Show Gist options
  • Select an option

  • Save iwadon/13426 to your computer and use it in GitHub Desktop.

Select an option

Save iwadon/13426 to your computer and use it in GitHub Desktop.
module M
def subclasses
@subclasses ||= []
end
def inherited(subclass)
subclasses << subclass
end
def const_missing(name)
subclasses.each do |subclass|
return subclass.const_get(name) if subclass.const_defined?(name)
end
super
end
end
class A
extend M
def x
C
end
end
class B < A
C = 100
end
p B.new.x # => 100
p A.new.x # => 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment