Within a block passed to "each" can I detect the last time t

Hi,

Does anyone know a way for the below code, to tell when the last block
is
called via “each” so that I can detect this and not add a superfluous
“&” to
the end of the string being built up?

postDataHash.each { |key, value|
  postDataString << "#{key}=#{value}&"
}

Tks
Greg

On Feb 15, 2007, at 1:49 PM, Greg H. wrote:

Does anyone know a way for the below code, to tell when the last
block is
called via “each” so that I can detect this and not add a
superfluous “&” to
the end of the string being built up?

Doesn’t exactly answer your question, but:

postDataHash.each { |key, value|
postDataString << “#{key}=#{value}&”
}

postDataString << postDataHash.map { |k, v| “#{k}=#{v}” }.join("&")

James Edward G. II

excellent - thanks James!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs