Created
April 28, 2009 18:06
-
-
Save kevinclark/103294 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
-------------------------------------------------------- Class#inherited | |
inherited(subclass) | |
------------------------------------------------------------------------ | |
Callback invoked whenever a subclass of the current class is | |
created. | |
Example: | |
class Foo | |
def self.inherited(subclass) | |
puts "New subclass: #{subclass}" | |
end | |
end | |
class Bar < Foo | |
end | |
class Baz < Bar | |
end | |
produces: | |
New subclass: Bar | |
New subclass: Baz |
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
Clio:~ kev$ irb | |
>> class Foo; end | |
=> nil | |
>> class Bar < Foo; end | |
=> nil | |
>> class Baz < Foo; end | |
=> nil | |
>> ObjectSpace.each_object(Class) {|c| puts "Subclass of Foo: #{c.inspect}" if c < Foo } | |
Subclass of Foo: Baz | |
Subclass of Foo: Bar | |
=> 400 | |
>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment