Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1060743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:22:25+00:00 2026-05-16T18:22:25+00:00

I want to iterate an array inside a Ruby heredoc. <<-BLOCK Feature: User logs

  • 0

I want to iterate an array inside a Ruby heredoc.

<<-BLOCK
Feature: User logs in
  In order to post content
  As an user
  I want to log in

<< Here i want to iterate scenarios >>
BLOCK

“scenarios” is an array I want to loop. For each element I want to print out:

Scenario: #{scenario}
  Given
  When
  Then

So for example if “scenarios” contains:

scenarios[0] = "User successfully logs in"
scenarios[1] = "User failed to log in"

I want the heredoc string to be:

<<-BLOCK
Feature: #{feature}
  In order to #{in_order_to}
  As #{as}
  I want #{i_want}

Scenario: User successfully logs in
  Given
  When
  And

Scenarios: User failed to log in
  Given
  When
  And
BLOCK

How do I do iterate inside a Ruby heredoc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:22:26+00:00Added an answer on May 16, 2026 at 6:22 pm

    You can do it but I’m not sure it is the most readable approach:

    s = <<-BLOCK
    Feature: User logs in
      In order to post content
      As an user
      I want to log in
    
    #{scenarios.map{|x|
    <<-INNERBLOCK
    Scenario: #{x}
      Given
      When
      Then
    INNERBLOCK
    }}
    
    BLOCK
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my array: $array = array(1,2,3,4,5,6,7,8,9,10); I want to iterate through the array 5
I want to iterate through an array of objects <% @users.each do |user| %>
I have got an array of objects in ruby and I want to iterate
I have an array inside an $.each function. I want to iterate through it
I want to iterate over an array of inputs that belong to certain class
I have the array: example = ['foo', 'bar', 'quux'] I want to iterate over
Here I am iterating through an array of NSDictionary objects (inside the parsed JSON
I want to iterate through a reference to an array of hashes without having
I have an array that I want to iterate over and delete some of
I have an array list: private ArrayList<PerfStatBean> statFilterResults; I want to iterate through it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.