Mat*_*att 3 ruby loops heredoc
你可以做一个循环和here-doc,像这样:
array.each do |ele|
a=<<-TEXT
ele
some stuff
TEXT
end
Run Code Online (Sandbox Code Playgroud)
谢谢
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
Run Code Online (Sandbox Code Playgroud)
结果是
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!
Run Code Online (Sandbox Code Playgroud)