Searching for combinations of words and numbers
I'm not a fan of the latter because the compact and flatten methods create new arrays.

Here's another variation with two additional style options: use of product to combine the two arrays, and each_with_object:

def generate_fields_3
  words   = ["foo", "bar", "bla"]
  numbers = [1, 2, 3]

  words.product(numbers).each_with_object([]) do |(word, number), fields|
    content = find_content(word, number)
    next if content.nil?

    fields &lt;&lt; {
      kind: word,
      value: content
    }
  end
end