Skip to Content
Course content

122: Timed Mock Assessment on Core Ruby

Click on the "Edit" button in the top corner of the screen to edit your slide content.

Think about the first time you took a driver's test. You already knew how to steer, how to brake, and how to check your mirrors. You'd practiced those individual movements a hundred times. But the actual test is different because there's an instructor with a clipboard and a ticking clock. Suddenly, you're not just "driving"—you're performing under pressure. You might forget a blinker not because you don't know how it works, but because your brain is juggling the stress of the evaluation.

That's exactly why we're doing this timed mock assessment. You've spent the last 121 lessons learning the "how" of Ruby—from the nuances of blocks and procs to the intricacies of class inheritance. Now, we need to shift from learning to performing. We're simulating that "clipboard" feeling so you can find out where your muscle memory fails before it happens in a real interview or a high-stakes production deadline.

Measuring Your Panic Threshold

In a relaxed environment, you can Google every syntax error. In a timed assessment, you have to trust your internal compiler. I want you to pay attention not just to whether your code works, but to where you hesitate. Do you freeze when you have to decide between map and reduce? Do you struggle to remember the exact syntax for a keyword argument? Those hesitations are the real "bugs" we're looking for here. They tell us exactly which parts of the core language need another pass of review.

The Core Competencies Under Fire

For this mock, I'm not looking for "clever" one-liners. I'm looking for the sturdy, reliable application of core Ruby. Specifically, I want to see you handle these three things without breaking a sweat:

  • Data Transformation: Taking a messy array of hashes and turning it into a structured report using Enumerable methods.
  • State Management: Building a class that maintains internal state correctly without leaking logic into the public API.
  • Edge Case Handling: Dealing with nil values or empty collections without the whole program crashing with a NoMethodError.

Avoiding the Rabbit Hole

Here is a piece of advice from someone who has failed plenty of these: if you spend more than five minutes staring at a single line of code, you've already lost the round. In a timed setting, the goal is a working solution, not a perfect one. If you can't remember the exact method name for a string manipulation, write a comment like # TODO: use the method that strips whitespace here and move on. Get the logic flowing first. You can polish the syntax once the skeleton of the program is standing.




📋 Practical Task

Timed Challenge: The Warehouse Inventory Auditor

Time Limit: 60 Minutes

Your task is to build a small system that audits warehouse stock. You must implement this without using any external gems, relying strictly on Ruby Core.

Requirements:

  • Create a Product class that initializes with a name, category, and quantity.
  • Create an Auditor class that takes an array of Product objects.
  • Implement a method in Auditor called low_stock_report(threshold). This should return a hash where the keys are the categories and the values are arrays of product names that fall below the given threshold.
  • Implement a method called total_inventory_value(price_map). The price_map will be a hash (e.g., {"Widget" => 10.0, "Gadget" => 20.0}). This method should calculate the total value of all items in the warehouse. If a product isn't in the price map, assume its value is 0.
  • Ensure your code handles an empty product list gracefully without crashing.

Success Criteria:


products = [
  Product.new("Laptop", "Electronics", 5),
  Product.new("Mouse", "Electronics", 2),
  Product.new("Desk Chair", "Furniture", 1),
  Product.new("Notebook", "Stationery", 20)
]
auditor = Auditor.new(products)

# Should return {"Electronics" => ["Mouse"], "Furniture" => ["Desk Chair"]}
puts auditor.low_stock_report(3) 

# Should return the correct sum based on the provided prices
prices = {"Laptop" => 1000, "Mouse" => 25, "Desk Chair" => 150, "Notebook" => 2}
puts auditor.total_inventory_value(prices) 
Rating
0 0

There are no comments for now.

to be the first to leave a comment.