Last active
October 7, 2016 22:39
-
-
Save kellylougheed/044adbe9ce74213adfa484e45ee98c1d to your computer and use it in GitHub Desktop.
Builds a class for a book and a textbook class that inherits from it. (Firehose Project Quiz #3)
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 Book | |
attr_accessor :title, :author | |
def initialize(title, author) | |
@title = title | |
@author = author | |
end | |
def read | |
puts "I'm reading #{@title} by #{@author}" | |
end | |
end | |
class Textbook < Book | |
def learn | |
puts "I'm learning from #{@title} by #{@author}" | |
end | |
end | |
hp = Book.new("Harry Potter", "J. K. Rowling") | |
hp.read | |
gibbon = Textbook.new("The Decline and Fall of the Roman Empire", "Edward Gibbon") | |
gibbon.learn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment