While loop in a here documents

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?

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.)

···

On Mon, 01 Dec 2008 17:33:06 -0800, equinox wrote:

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?

--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/

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

  robert

···

On 02.12.2008 02:33, equinox wrote:

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?

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

···

On Dec 1, 7:08 pm, Ken Bloom <kbl...@gmail.com> wrote:

On Mon, 01 Dec 2008 17:33:06 -0800, equinox wrote:
> 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?

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.)

--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.http://www.iit.edu/~kbloom1/

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

···

On Mon, Dec 1, 2008 at 8:14 PM, equinox <aditya15417@gmail.com> wrote:

On Dec 1, 7:08 pm, Ken Bloom <kbl...@gmail.com> wrote:
> On Mon, 01 Dec 2008 17:33:06 -0800, equinox wrote:
> > 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?
>
> 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.)
>
> --
> Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
> Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/

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

No. You'll have to put the loop outside the string.

···

On Mon, 01 Dec 2008 19:15:29 -0800, equinox wrote:

On Dec 1, 7:08 pm, Ken Bloom <kbl...@gmail.com> wrote:

On Mon, 01 Dec 2008 17:33:06 -0800, equinox wrote:
> 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?

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.)

--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of
Technology.http://www.iit.edu/~kbloom1/

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

--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/