n-ruby迭代

n-ruby迭代,ruby,iteration,Ruby,Iteration,如何创建一个不是按1而是按n进行迭代的循环 在本例中,我如何读取五行,下一次迭代如何读取其他五行,依此类推 example = '<div id="post-editor" class="post-editor"> <div class="wmd-container"> <div id="wmd-button-bar" class="wmd-button-bar"></div> <textarea

如何创建一个不是按1而是按n进行迭代的循环

在本例中,我如何读取五行,下一次迭代如何读取其他五行,依此类推

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;">&nbsp;</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
example=”
保存的草稿
丢弃的草稿
'
以身作则
您可以执行以下操作:

example.each_line.each_slice(5) { |lines| # do something with lines }