-
-
Save Tubbz-alt/cd9fb12b91426e2cbd2387fe26c48a4d 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
# Models | |
class Animal < ActiveRecord::Base | |
parent_model | |
end | |
class Dolphin < Animal | |
parent_model exposes: [:swim, :chirp] | |
child_of :animal | |
def swim | |
puts "Swooooshhhhhhhh" | |
end | |
def chirp | |
puts "Eh-eh-eh ehh ehhh eh ehh" | |
end | |
end | |
class BottleNoseDolphin < Dolphin | |
child_of :dolphin | |
end | |
# Migration | |
class Animals < ActiveRecord::Migration | |
def self.up | |
create_table :animals do |t| | |
t.integer :heir_id | |
t.string :heir_type | |
t.boolean :invertebrate | |
t.timestamps | |
end | |
end | |
def self.down | |
drop_table :animals | |
end | |
end | |
class Dolphin < ActiveRecord::Migration | |
def self.up | |
create_table :dolphins do |t| | |
t.integer :heir_id | |
t.string :heir_type | |
t.boolean :smelly | |
end | |
end | |
def self.down | |
drop_table :dolphins | |
end | |
end | |
class BottleNoseDolphins < ActiveRecord::Migration | |
def self.up | |
create_table :bottle_nose_dolphins do |t| | |
t.boolean :evil | |
end | |
end | |
def self.down | |
drop_table :bottle_nose_dolphins | |
end | |
end | |
# Runtime | |
flippy = BottleNoseDolphin.new | |
flippy.chirp # Good boy! | |
flippy.invertebrate = false | |
flippy.smelly = false | |
flippy.evil = true | |
flippy.save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment