Here’s a refactoring example for a simple Ruby math problem using the

`inject`

method.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 {...`

- khannz likes this
- rosadi12 reblogged this from thoughtbot
- collegeimprovements likes this
- tyraeltong reblogged this from thoughtbot
- tyraeltong likes this
- danielpietzsch likes this
- miss-turtle likes this
- dallas likes this
- turing-machine reblogged this from thoughtbot and added:
Functional programming patterns are awesome for this kind of problem. I had a job interview two months ago where I was...

- turing-machine likes this
- thoughtbot posted this