Last active
August 29, 2015 13:56
-
-
Save agile/9137372 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 Parent < ActiveRecord::Base | |
# assume there's a varchar field on the table called "name" | |
def name | |
puts "Holla from tha Parent!" | |
super | |
read_attribute(:name) || "default value!" | |
end | |
end | |
class Child < Parent | |
def name | |
puts "Holla from tha Child!" | |
super | |
end | |
end | |
irb> c = Child.find(123) | |
Child Load (0.5ms) SELECT "parents".* FROM "parents" WHERE "parents"."type" IN ('Child') AND "parents"."id" = $1 LIMIT 1 [["id", 123]] | |
=> #<Child id: 123, type: "Child", name: nil> | |
irb> c.name | |
Holla from tha Child! | |
=> nil | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment