title: Ruby: Split string at character, counting from the right side
body: <p>Short version -- How do I do Python rsplit() in ruby?</p>
  
  <p>Longer version -- If I want to split a string into two parts (name, suffix) at the first '.' character, this does the job nicely:</p>
  
  <pre><code>name, suffix = name.split('.', 2)
  </code></pre>
  
  <p>But if I want to split at the <em>last</em> (rightmost) '.' character, I haven't been able to come up with anything more elegant than this:</p>
  
  <pre><code>idx = name.rindex('.')
  name, suffix = name[0..idx-1], name[idx+1..-1] if idx
  </code></pre>
  
  <p>Note that the original name string may not have a dot at all, in which case name should be untouched and suffix should be nil; it may also have more than one dot, in which case only the bit after the final one should be the suffix.</p>