Last active
March 23, 2016 07:52
-
-
Save k-hamada/4e509eb6f05a9fd790a3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require "active_record" | |
class Mother < ActiveRecord::Base | |
def self.inherited(subclass) | |
puts "Base Class: #{self}" | |
puts "New subclass: #{subclass}" | |
end | |
end | |
class Taro < Mother | |
end | |
# => Base Class: Mother | |
# => New subclass: Taro | |
Object.const_set :Jiro, Class.new(Mother) | |
# => Base Class: Mother | |
# => New subclass: #<Class:0x007fd8f3adb640> |
This file contains hidden or 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 GreatMother | |
def self.inherited(subclass) | |
puts "Base Class: #{self}" | |
puts "New Subclass: #{subclass}" | |
super | |
end | |
end | |
class ChildTaro < GreatMother | |
end | |
# => Base Class: GreatMother | |
# => New Subclass: ChildTaro | |
Object.const_set :ChildJiro, Class.new(GreatMother) | |
# => Base Class: GreatMother | |
# => New Subclass: #<Class:0x007fd150834248> | |
p ChildJiro.superclass | |
# => GreatMother |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment