Ruby here-doc with loop

Can you make a loop here too-doc, something like this:

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

thank

+3
source share
1 answer
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

leads to

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!
+5
source

Source: https://habr.com/ru/post/1777235/


All Articles