title: Functional approach to joining an Array of values with varying separator?
body: <p>I'm looking for a functional way to perform this messy procedural logic:</p>
  
  <pre><code>values = [a, b, c, d, e, f]
  last_value = nil
  string = ""
  values.each do |v|
    string &lt;&lt; if last_value &amp;&amp; last_value.special?
      "/x/" + v.name.to_s
    else
      "/" + v.name.to_s
    end
    last_value = v
  end
  </code></pre>
  
  <p>I basically have an array of objects (all the same type) and need to join their <code>#name</code> attributes, but following an object that has a particular characteristic, I need a different separator.</p>
  
  <p>This is an easily solved problem, but I'm looking for the cleanest, most functional approach.  I first dived into <code>#inject</code>, but you lose the previous value at each iteration, so I couldn't make that work.  Any ideas?</p>
  
  <p>I'd love to post the real code instead of pseudo code, but it's really dense and complex DataMapper Relationship stuff, so you probably couldn't just run it anyway, sorry :(</p>