Here’s a refactoring example for a simple Ruby math problem using the
injectmethod.The goal is to generate an n by n multiplication matrix. Pretty straightforward. Let’s make a first pass:
def multiplication_table(n) results = [] (1..n).each do |row_index| row = [] (1..n).each {...