title: Ruby: Remove first and last element of an Array - why the solution works one way & not the other
body: <p>I's like to know why the second solution works but the first one, which has chained methods, doesn't work.</p>
  
  <p>This chained method doesn't work:</p>
  
  <pre><code>nopers = [5, 6, 7, 8, 9]
  
  class Array
    define_method(:trimy) do
      self.shift().pop()
    end
  end
  </code></pre>
  
  <p>When I test it, nopers.trimy(), it gives an undefined error message. "method 'pop' for 1:Fixnum, in 'block in '" and only executes the .pop() method, removing the 5.</p>
  
  <p>But, this version works:</p>
  
  <pre><code>yuppers = [1, 2, 3, 4, 5, 6]
  
  class Array
    define_method(:trim) do
      self.shift()
      self.pop()
    end
  end
  
  yuppers.trim()
  </code></pre>
  
  <p>When I test it, yuppers gives me: [2, 3, 4, 5]</p>