title: Inject in array
body: <p>I am trying to do some calculation like the following. <code>option</code> is an empty hash and <code>aes</code> is an array.</p>
  
  <pre><code>options = {}
  aes = [1,2]
  test = aes.inject([]) do |array, value|
    array &lt;&lt; value + 2
    array &lt;&lt; value -1 if options[:calculation]  # here options[:calculation] will be nil 
  end
  </code></pre>
  
  <p>I debugged and found that the value of <code>test</code> is <code>nil</code>. The output of <code>array &lt;&lt; value -1 if options[:calcuation]</code> is <code>nil</code>, and I want to return the calculated value in <code>test</code>. For resolving this issue, I am using the code below, where <code>aes</code> is an array:</p>
  
  <pre><code>options = {}
  aes = [1,2]
  test = aes.inject([]) do |array, value|
    array &lt;&lt; value + 2
    array &lt;&lt; value -1 if options[:calculation]  # here options[:calculation] will be nil 
    array # I am using `array` here
  end
  </code></pre>
  
  <p>Is this correct, or is there any alternate way to do this?</p>