我想在Ruby heredoc中迭代一個數組。heredoc裏面的Ruby語法?
<<-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
「場景」是我想要循環的數組。對於每一個元素我想打印出來:
Scenario: #{scenario}
Given
When
Then
因此,舉例來說,如果「場景」載:
scenarios[0] = "User successfully logs in"
scenarios[1] = "User failed to log in"
我想定界符字符串是:
<<-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
我如何在Ruby heredoc裏面迭代?
爲什麼它打敗了heredocs的目的?能夠在heredocs中擁有動態數據不行嗎? – 2010-09-10 20:30:04
Btw。這不起作用\ n被解釋爲文本而不是新行。 – 2010-09-10 20:33:03
奇怪。我仍然有\ n。以下是腳本和文件的樣子:http://pastie.org/1150945 – 2010-09-10 20:56:52