- 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
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.
- 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.
- Pseudocode
- Initial Solution
- Refactored Solution
- Reflect
- Sync your changes (push your solution) to Github
- Review