title: How do I extract a submatrix from a matrix in ruby
body: <p>What would be the idiomatic way of extracting a submatrix from a matrix in ruby.</p>
  
  <p>I have a matrix like, this is an object of <code>Matrix</code></p>
  
  <pre><code>[131, 673, 234, 103, 18]
  [201, 96, 342, 965, 150]
  [630, 803, 746, 422, 111] 
  [537, 699, 497, 121, 956] 
  [805, 732, 524, 37, 331]
  </code></pre>
  
  <p>I'm looking for a method with a signature like
  <code>matrix.submatrix(1,1)</code> this should return</p>
  
  <pre><code>[96, 342, 965, 150]
  [803, 746, 422, 111] 
  [699, 497, 121, 956] 
  [732, 524, 37, 331]
  </code></pre>
  
  <p><code>matrix.submatrix(2,2)</code> would return</p>
  
  <pre><code>[746, 422, 111] 
  [497, 121, 956] 
  [524, 37, 331]
  </code></pre>
  
  <p>I browsed through the <a href="http://ruby-doc.org/stdlib-1.9.3/libdoc/matrix/rdoc/Matrix.html" rel="nofollow">rubydoc</a> but couldn't find any method that would give me what I wanted. How would I do this in ruby?</p>
  
  <p>For a 2D array I have come up with </p>
  
  <pre><code>def submatrix(matrix)
    submatrix = matrix.collect{|row| row.slice(1..-1)}
    # Pop off the first row
    submatrix[1..-1]
  end
  </code></pre>
  
  <p>I am wondering if I should reinvent the wheel or could I use something from the Matrix class.</p>