Giter VIP home page Giter VIP logo

rails-mini-course-sprint1-mod2-student--starter's Introduction

Ruby on Rails - Ruby & Ruby on Rails Basics - Object-oriented Programming - Project

For today's challenge we are going to act as librarians that are trying to keep track of our books.

Setup

First, we need to clone the repository and then run irb in the terminal.

Instructions

  1. Create a Book class (in a file called book.rb) so that we can track how many copies of a book we have and whether we have personally finished reading it or not.

    • The Book class should have title, author, finished, and count instance variables.
    • You should be able to pass in the title and author values when you instantiate a book, but only those two attributes.
      • Example: Book.new("Practical Object-Oriented Design in Ruby", "Sandi Metz").
    • finished is a boolean and should default to false.
    • count is an integer and should default to 3.
    • All of the instance variables should be set in the initialize method.
  2. Test out your book class using irb.

  3. Use attr_ macros to provide access to the instance variables.

    • title and author should only be readable.
    • finished should only be writeable.
    • count should be readable and writeable.
  4. Create AudioBook (audio_book.rb) and ComicBook (comic_book.rb) classes that inherit from Book.

    • Add a listen method to AudioBook that sets the finished value to true.
    • Add a read method to ComicBook that sets the finished value to true
  5. Add a recommended_books class method to the Book class that creates and returns an array of recommended books

    • Add the following code inside of the recommended_books class method:
  [
    Book.new("The Well-Grounded Rubyist", "David A. Black"),
    Book.new("Practical Object-Oriented Design in Ruby", "Sandi Metz"),
    Book.new("Effective Testing with RSpec 3", "Myron Marston"),
  ]
  • Test out the recommended_books class method
  1. Create a Lendable module with a lend method that decrements the current count by one.

    • Prevent the count from going below 0 in the lend method
    • Mixin the module into Book
    • Test that you can lend a book by verifying the count has reduced

rails-mini-course-sprint1-mod2-student--starter's People

Contributors

bnbry avatar mattmccarley avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.