This file contains hidden or 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
# Exercises - write two methods in the book class that make the failing tests pass | |
# Extra Credit - refactor the way page_count is handled so it is more DRY | |
# Extra Extra Credit - add a humanize method to the String class so you can take a string like this: | |
# 'page_count' and turn it into this 'page count' | |
# Be sure to add tests for your extra credit!! | |
class Book | |
attr_accessor :title, :author, :page_count, :pages | |
This file contains hidden or 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
Exercise | |
- Make a Table object class | |
- Define at least 5 properties of a Table (legs, material, items_on_it, etc…) | |
- Define an initialize method that sets one or more of the attributes when you call Table.new | |
- Define a pretty_print method that prints out some useful information about your table | |
- Email us a link to your code in a Gist | |
Extra Credit: | |
- Make tests for your Table class | |
- Try the Exercises in the Gist for the Book class |
This file contains hidden or 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
# Assignment: Fill in this Table class so the tests pass! | |
# Exercise Details: | |
#- Make a Table object class | |
#- Define at least 5 properties of a Table (legs, material, items_on_it, etc…) | |
#- Define an initialize method that sets one or more of the attributes when you call Table.new | |
#- Define a pretty_print method that prints out some useful information about your table | |
#- Email us a link to your code in a Gist | |
# Extra Credit: |
This file contains hidden or 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
#1 First open your terminal program and type cd to go to your home directory: | |
cd | |
#2 To create a new rails application called q_man using postgresql: | |
rails new q_man -d postgresql | |
#3 Enter the application directory: | |
cd q_man | |
#4 Start the local webserver | |
rails s |
This file contains hidden or 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
def test_wg_pretty_prints_stem_length_and_volume | |
assert_equal "This wine glass is cool. It has a stem length of 5 and a volume of 6500ml", @wg.pretty_print_stuff | |
end |
This file contains hidden or 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
# Make the existing tests pass. | |
# Add 2 more tests and methods for: | |
## 1. Another print method for material, volume, and stem_length all together | |
## 2. A method that calculates and returns the percent of the glass that is full when you pass in the | |
### volume of liquid in the glass. | |
### This calculation is: (volume_passed_to_method / volume_of_wine_glass) * 100 | |
class WineGlass | |
attr_accessor :material, :volume, :stem_length | |
def pretty_print_material |
This file contains hidden or 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
# Write a Ruby script that prints the numbers from 1-100, | |
# replacing every multiple of 3 with the word Fizz, | |
# replacing every multiple of 5 with the word Buzz, | |
# and replacing every multiple of both with the word FizzBuzz | |
# | |
# Extra Credit: your script does not use if statements (or unless!), while loops, or switch statements | |
# | |
# Your Output should look like this: | |
renee$ ruby fizz_buzz.rb | |
1 |
This file contains hidden or 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
# Write a Ruby script that prints the numbers from 1-100, | |
# replacing every multiple of 3 with the word Fizz, | |
# replacing every multiple of 5 with the word Buzz, | |
# and replacing every multiple of both with the word FizzBuzz | |
# | |
# My idea was to create an array of 1-100, then convert that to a string so I could use successive gsubs to replace the multiples with the correct words. When I try to run it I get "undefined method 'gsub' for #<Array>. I've discovered I'm a lot better at editing/adding to things that already exist than trying to set up a script from scratch. Not sure if I'm even on the right track here and I could definitely use your input. Thanks! | |
array = Array (1..100) | |
puts array | |
numbers = array.to_s |