私は Ruby で PHP のようなループを頻繁に使用していることに気づきました。言語の残りの部分が非常にきちんとしていると、違和感を覚えます。私は次のようなコードで終わります:
conditions_string = ''
zips.each_with_index do |zip, i|
conditions_string << ' OR ' if i > 0
conditions_string << "npa = ?"
end
# Now I can do something with conditions string
こんなことができたらいいなと思います
conditions_string = zips.each_with_index do |zip, i|
<< ' OR ' if i > 0
<< "npa = ?"
end
Rubyでブロックを使用して変数を設定する「きちんとした」方法はありますか?