title: How to Find the Middle Character(s) in Ruby?
body: <p>I'm trying to write a method in Ruby that:</p>
  
  <ol>
  <li><p>if the string length is even numbers it will return the middle two characters and,</p></li>
  <li><p>if the string length is odd it will return only the middle character </p></li>
  </ol>
  
  <p>i put together this code, but it is not working:</p>
  
  <pre><code>def the_middle(s)
     if s.length % 2 == 0
        return s.index(string.length/2-1) &amp;&amp; s.index(string.length/2)
     else
        return s.index(string.length/2).round 
     end
  end
  </code></pre>
  
  <p>I think the problem is in the syntax, not the logic, and I was hoping someone could identify where the syntax error might be. </p>
  
  <p>I really appreciate your help! </p>