while loop in a here documents

E

equinox

I have a here documents of something like this:

form = <<"DONE"

while( bla ..bla .. bla) do

this

DONE


How can I do a while loop inside a here documents in ruby? Is it
possible?
 
E

equinox

If you want to use erb, then you can do something like that.

require 'erb'

erb=ERB.new <<-'DONE'
<% 5.times do %>
this text is repeated
<% end %>
DONE
form=erb.result(binding)

Be warned that you have to place the commands correctly to avoid getting
extra newlines. (This is mostly intended for HTML templating, where
newlines don't matter.)

I am not using erb unfortunately, anyway to go around this?
 
V

Victor H. Goff III

[Note: parts of this message were removed to make it a legal post.]

Something like this? Though this has other problems...
STDOUT.sync = true
my_text = <<-FINISHED
Note the sequence of when these things are written.
#{3.times do
puts "Hello"
end
} times a greeting was written.
end of my text
FINISHED
puts my_text
 
R

Robert Klemme

I have a here documents of something like this:

form = <<"DONE"

while( bla ..bla .. bla) do

this

DONE


How can I do a while loop inside a here documents in ruby? Is it
possible?

What exactly are you trying to achieve? Do you want to have repeated
content from the here doc?

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top