ruby の式展開の仕方をまとめました。一番下のやつをさっき知ってびっくりしたので、忘れぬうちにメモ
test.rb
hoge = "__hoge__"
# 基本的な式展開
puts "#{hoge}" #=> __hoge__
# 式展開の中では普通にコードがかける
puts "#{hoge + hoge.upcase}" #=> __hoge____HOGE__
# printf 風
puts "%d" % 12345 #=> 12345
# 複数の場合はArrayで
puts "%d, %d" % [12345, 56789] #=> 12345, 56789
# ハッシュも渡せる
puts "%{hoge}, %{fuga}" % {:fuga => "__fuga__", :hoge => "__hoge__" } #=> __hoge__, __fuga__