Content

Resources

Comments

Getting Started

Warmup 1: Ruby Methods

The following methods don't even require OOP, so just write them out as individual methods.

If you find yourself unsure of what's going on inside a method, don't forget to use binding.pry to pause its execution and examine its variables. This is a critical tool to get familiar with!

My_reverse

Build a method that reverses any string you put into it, and don't use the built-in reverse.

puts my_reverse("Blah!")
#=> !halB

Fibonacci Sequence

Write a method that takes an integer and spits out an array of that many elements of the Fibonacci Sequence, which starts with 0 and 1 and computes the next element by adding the most recent two elements together.

fibs(3)
#=> [0,1,1]
fibs(8)
#=> [0,1,1,2,3,5,8,13]

Warmup 2: Benchmarker

Write a method, my_benchmark, that takes a parameter number_of_times and a block and returns how long that block took to run that block, that many times. Remember, you can get the current time using Time.now, and you can subtract one time from another to get a duration in seconds.

my_benchmark(10000) { puts "hi" }
#=> 0.056918

Warmup 3: Rebuild the Enumerable Methods

The Enumerable module is often misunderstood, so you'll get to build it from the ground up. After this, you'll never wonder what the heck these things are actually doing.

My_each

Create a method my_each which extends the Array class and has identical functionality to Ruby's native each method (obviously don't use each in the implementation). Make it take either a block or a proc.

My_map

Create a method my_map which extends the Array class and has identical functionality to Ruby's native map method. You can use your my_each method to implement this. Make it take either a block or a proc.

> [1,2,5].my_map do |item|
> item ** 2
> end
#=> [1,4,25]

My_select

Create a method my_select which extends the Array class and has identical functionality to Ruby's native select method. You can use your my_each method to implement this. Make it take either a block or a proc.

My_inject

Create a method my_inject which extends the Array class and works the same as Ruby's native inject method. You can use your my_each method to implement this. Make it take either a block or a proc.

> [1,2,5].my_inject(0) do |memo, item|
> memo + item
> end
#=> 8

OOP 1: Rock Paper Scissors

Rock Paper Scissors is as simple as object-oriented programming challenges get, so it'll be another good warmup.

Your Task

Create a command line Rock-Paper-Scissors game, starting with one player against the computer. Think through what you need beforehand and write it down. What classes do you need? What methods? Then get started.

Start with one player against the computer and then add 2-player mode.

OOP 2: Tower of Hanoi

Hopefully, you're pretty familiar with the game Tower of Hanoi by this point. For this assignment, you'll need to adapt your Tower of Hanoi game to OOP. Since last time you built this using a single giant script, there is plenty of room for improvement.

Rebuild Tower of Hanoi using good object-orientation. That means separating out your functionality into logical objects with methods and instance variables.

Wrapping Up

You've built a lot of stuff this assignment. Great work!

The final step is to submit the assignment back to the upstream repo on Github as you have with the others.