Reputation: 23
How can I create a loop that iterates not by one, but by n?
In this example how can I read five lines, and the next iteration read other five lines, and so on?
example = '<div id="post-editor" class="post-editor">
<div class="wmd-container">
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="wmd-input" name="post-text" cols="92" rows="15" tabindex="101"></textarea>
</div>
<div class="fl" style="margin-top: 8px; height:24px;"> </div>
<div id="draft-saved" class="draft-saved community-option fl" style="margin-top: 8px; height:24px; display:none;">draft saved</div>
<div id="draft-discarded" class="draft-discarded community-option fl" style="margin-top: 8px; height:24px; display:none;">draft discarded</div>
<div id="wmd-preview" class="wmd-preview"></div>
<div></div>
<div class="edit-block">
<input id="fkey" name="fkey" type="hidden" value="7668dcce69f925d656bc4019c29fd061">
<input id="author" name="author" type="text">
</div>
</div>'
puts example
Upvotes: 2
Views: 95
Reputation: 66837
You can do:
example.each_line.each_slice(5) { |lines| # do something with lines }
Upvotes: 3