I often use PHP-like loops in Ruby, and it doesn't feel like it when the rest of the language is so neat. I end up with the code as follows:
conditions_string = ''
zips.each_with_index do |zip, i|
conditions_string << ' OR ' if i > 0
conditions_string << "npa = ?"
end
It seems to me that I can do something like this
conditions_string = zips.each_with_index do |zip, i|
<< ' OR ' if i > 0
<< "npa = ?"
end
Is there an Inactive way to set a variable with a block in Ruby?
source
share