title: Ruby (Monkey Patching Array)
body: <p>Back for more help on my coursework at Bloc. Decided to bring you guys in on a problem I'm having with Monkey Patching the Array Class. This assignment had <strong>8 specs</strong>  to be met and I'm stuck now with one left and I'm not sure what to do. </p>
  
  <p>I'm only going to give you the RSpecs and written requirements for the part that I'm having trouble w/ since everything else seems to be passing. Also I'll include the starter scaffolding that they gave me to begin with so there's no confusion or useless additions to the code.</p>
  
  <hr>
  
  <p>Here are the written requirements for the Array Class Monkey Patch:</p>
  
  <ul>
  <li><p>Write a new <code>new_map</code> method that is called on an instance of the <code>Array</code> class. It should use the array it's called on as an implicit (<code>self</code>) argument, but otherwise behave identically. (<strong>INCOMPLETE</strong>)</p></li>
  <li><p>Write a new_select! method that behaves like the select, but mutates the array on which it's called. It can use Ruby's built-in collection select method. (<strong>COMPLETE</strong>)</p></li>
  </ul>
  
  <hr>
  
  <p>Here are the RSpecs that need to be met regarding the Array class: </p>
  
  <blockquote>
    <p>Note: "returns an array with updated values" Is the only Spec not passing.</p>
  </blockquote>
  
  <pre><code>describe Array do
    describe '#new_map' do
      it "returns an array with updated values" do
        array = [1,2,3,4]
        expect( array.new_map(&amp;:to_s) ).to eq( %w{1 2 3 4} )
        expect( array.new_map{ |e| e + 2 } ).to eq( [3, 4, 5, 6] )
      end
  
      it "does not call #map" do
        array = [1,2,3,4]
        array.stub(:map) { '' }
        expect( array.new_map(&amp;:to_s) ).to eq( %w{1 2 3 4} )
      end
  
      it "does not change the original array" do
        array = [1,2,3,4]
        expect( array.new_map(&amp;:to_s) ).to eq( %w{1 2 3 4} )
        expect( array ).to eq([1,2,3,4])
      end
    end
  
    describe '#new_select!' do
      it "selects according to the block instructions" do
        expect( [1,2,3,4].new_select!{ |e| e &gt; 2 } ).to eq( [3,4] )
        expect( [1,2,3,4].new_select!{ |e| e &lt; 2 } ).to eq( [1] )
      end
  
      it "mutates the original collection" do
        array = [1,2,3,4]
        array.new_select!(&amp;:even?)
        expect(array).to eq([2,4])
      end
    end
  end
  </code></pre>
  
  <hr>
  
  <p>Here is the scaffolding they started me with: </p>
  
  <pre><code>class Array
    def new_map
    end
  
    def new_select!(&amp;block)
    end
  end
  </code></pre>
  
  <hr>
  
  <p>Lastly, here is my code:</p>
  
  <pre><code>class Array
    def new_map 
      new_array = []
      self.each do |num|
        new_array &lt;&lt; num.to_s
      end
      new_array
    end
  
    def new_select!(&amp;block)
      self.select!(&amp;block)
    end
  end
  </code></pre>