Test Yourself: Intermediate Ruby

Making sure you've covered everything you need to know for the coming projects.

Scroll down...




Test your knowledge with the questions below. Make sure you can answer them before starting on the projects. All of the answers are contained in the previous lessons.

Blocks, Procs and Lambdas

  • What are blocks?
  • Why are blocks called "anonymous functions"?
  • What are two ways to declare a block?
  • What is "returned" by a block and how is this different from a normal method's return statement?
  • How does yield work?
  • How can you pass arguments to a block using yield?
  • Why are blocks so useful?
  • How can you test whether a block was passed in?
  • What class is a block?
  • What is a Proc?
  • How do you save a block to a variable using a Proc?
  • How can you use a Proc in a method?
  • How do you create a method designed to take a Proc?
  • What are "Closures"?
  • What is a "Lambda" and what can you do with it that you can't with a Proc?
  • What is a "Method" and what can you do with it that you can't with a Lambda?

The Enumerable Module

  • What is a "Module"?
  • What is the prerequisite for including Enumerable in your classes?
  • How does each work?
  • How does each_with_index work?
  • What does select do? What does it return?
  • What is collect? map?
  • What is returned by map?
  • What's different about using Enumerable methods on a Hash instead of an Array?
  • What is inject / reduce and why is it called "reduce"?
  • What (basically) is an Enumerator?

Pass by Reference

  • What does "Pass By Reference" mean? "Pass By Value"?
  • Which of these is Ruby?
  • When you pass an object as an argument into a method, what are you actually passing?
  • What's the difference between "Destructive" and "Non-Destructive" functions?
  • Why isn't = destructive?
  • How do you create a duplicate object with a new object_id that's safe to modify?
  • What are the limitations of this?

Best Practices for Working with Methods

  • How many things should a method do?
  • What goes in a method?
  • What's the rough maximum size your methods should be?
  • Should your method modify its arguments?
  • How should you name methods?
  • What does self refer to?

Other Ruby Tidbits

  • How do you check whether something is nil?
  • What is the empty method used for?
  • What's the difference between p, puts, and print?
  • What are "Assignment Shorthand" operators?
  • What is "Parallel Assignment"?

Throwing and Handling Errors

  • When is an error typically thrown?
  • What is the ultimate superclass of all error classes in Ruby?
  • How do you use begin and rescue to recover from an error in a piece of code?
  • How do you rescue a specific type of exception?
  • What does ensure do?
  • How do you raise an error yourself?
  • How do you get access to the originally raised Exception in your rescue code?
  • How do you make an exception of your own?
  • What class should your custom exceptions inherit from?
  • Should you use exceptions to control the flow of your program?
  • How can you use throw and catch for flow control?
  • How can you pass a variable from your throw to your catch?

Debugging Tips

  • What's the first step of every debugging approach?
  • What is the byebug gem and how does it work?
  • What is the pry REPL and why is it useful?
  • How do you set a breakpoint in your code so you can stop it and inspect the state?
  • How do you restart the script or step through it incrementally?

Sign up to track your progress for free

There are ( ) additional resources for this lesson. Check them out!

There are no additional resources for this lesson just yet!

Sorry, comments aren't active just yet!

Next Lesson: Procedural Tower of Hanoi