Skip to content

Instantly share code, notes, and snippets.

@tiagopog
Created March 31, 2015 22:13
Show Gist options
  • Save tiagopog/a37db867d224040dcfd1 to your computer and use it in GitHub Desktop.
Save tiagopog/a37db867d224040dcfd1 to your computer and use it in GitHub Desktop.
STI example.
class Vehicle < ActiveRecord::Base
attr_accessor :direction
validates :name, presence: true
end
class Car < Vehicle
def turn_wheel(direction)
@direction = direction
puts "wheel was turned to the #{direction}"
end
end
class Bike < Vehicle
def turn_handlebar(direction)
@direction = direction
puts "handlebar was turned to the #{direction}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment