Created
October 17, 2014 00:08
-
-
Save elskwid/eaa2518ca69f7cef1c60 to your computer and use it in GitHub Desktop.
Ruby on Rails Fundamentals Warmup Day 04
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
# Note: run this file in ruby like this: | |
# $ ruby day04.rb | |
# This is a Ruby class | |
class ReadingMaterial | |
def initialize(contents = nil) | |
@contents = contents | |
end | |
# reader / getter | |
def contents | |
@contents | |
end | |
# writer / setter | |
def content=(new_contents) | |
@contents = new_contents | |
end | |
def printed? | |
:maybe | |
end | |
def ReadingMaterial.can_be_read? | |
true | |
end | |
def can_be_read? | |
self.class.can_be_read? | |
end | |
end | |
# This is also a Ruby class. | |
class Book < ReadingMaterial | |
end | |
# 1. What does the `<` above tell us? | |
# 2. Book is a class but it is also a what? | |
# HINT: It is a _blank_ of ReadingMaterial. | |
# 3. Create a new book and assign it to a variable named book | |
# 4. What do you expect to see when this is run? (uncomment to see it) | |
# puts "Is the book printed? #{book.printed?}" | |
# Here is another class. | |
class EBook < Book | |
def printed? | |
false | |
end | |
end | |
# 5. Create a new ebook and assign it to a variable | |
# 6. Display if the ebook is printed or not | |
class PaperbackBook < Book | |
def printed? | |
true | |
end | |
end | |
class Magazine < ReadingMaterial | |
def initialize(special_cover = false, contents = nil) | |
@special_cover = special_cover | |
end | |
def special_cover? | |
@special_cover | |
end | |
end | |
# 7. Create a new PaperbackBook and a new Magazine, assigned to variables | |
# 8. Display interesting things about them | |
# 9. How could we shorten the class definition of ReadingMaterial? | |
# HINT: We can use something Ruby provides... | |
### The rest of these are in our rails project | |
# 10. Start the Rails console in our project directory. | |
# HINT: use the rails command and a subcommand to do this. Don't forget | |
# to prefix with 'bin/'. | |
# 11. How many courses do you have in your database? | |
# 12. Find the first course in our database. | |
# 13. What does CRUD stand for? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://bit.ly/1pi7I2Y