开发者

ruby here-doc with a loop

开发者 https://www.devze.com 2023-01-27 01:14 出处:网络
Ca开发者_StackOverflown you do a loop andhere-doc, something like this: array.each do |ele| a=<<-TEXT

Ca开发者_StackOverflown you do a loop and here-doc, something like this:

array.each do |ele|
  a=<<-TEXT
   ele
   some stuff
  TEXT
end

Thanks


array = %w[one two many]

array.each do |ele|
  a=<<-TEXT
  This is some text and
  this --> #{ele} <-- is the ele!

  TEXT

  puts a
end

results in

This is some text and
this --> one <-- is the ele!

This is some text and
this --> two <-- is the ele!

This is some text and
this --> many <-- is the ele!
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号