Skip to content

Latest commit

 

History

History

2_die

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Week 5 Home

U2.W5: Die Class 2: Arbitrary Symbols

Learning Objectives

  • Break down problems into implementable pseudocode
  • Implement a basic Ruby class and identify when to use instance variables
  • Use if/else statements, string methods, while/until loops, Enumerable#each methods
  • Find and use built-in Ruby methods to solve challenges

Background

Working off your previous Die class from Die Class 1, implement a new Die class which takes an array of strings as its input. When Die#roll is called, it randomly returns one of these strings. If Die.new is passed an empty array, raise an ArgumentError. It should work like this:

die = Die.new(['A', 'B', 'C', 'D', 'E', 'F'])
die.sides # still returns the number of sides, in this case 6
die.roll # returns one of ['A', 'B', 'C', 'D', 'E', 'F'], randomly

Just to reiterate, in the previous exercise you passed in a number of sides, sides, and the labels were assumed to be the integers 1..sides. Now we're passing in a list of arbitrary labels. We could use this to represent a Dreidel or Boggle dice, for example.

Directions

  1. Run the Rspec tests, and then translate at least 3 of the tests into Driver Test Code and include it in the driver code section. If the tests are failing to catch a problem, try writing your own driver test code for it.
  2. Pseudocode
  3. Initial Solution
  4. Refactored Solution
  5. Reflect
  6. Sync your changes (push your solution) to Github
  7. Review