Skip to content

Instantly share code, notes, and snippets.

@k-hamada
Last active March 23, 2016 07:52
Show Gist options
  • Save k-hamada/4e509eb6f05a9fd790a3 to your computer and use it in GitHub Desktop.
Save k-hamada/4e509eb6f05a9fd790a3 to your computer and use it in GitHub Desktop.
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>
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