I am trying to expand an array containing two hash (: company,: top_rate_campaign) using each.with_index () in a RubyOnRails application.

syntax error, unexpected tLABEL
... ach.with_index (1) do | (company :, top_rate_campaign :), rank |
... ^ ~~~~~~~
Applicable source code
<% companies.each.with_index (1) do | (company :, top_rate_campaign :), rank |%>
What I tried

<% companies.each do | company :, top_rate_campaign: |%>
It has been confirmed that it is possible to deploy without problems by the method that does not add index like.

Supplemental information (FW/tool version, etc.)

ruby 2.6.3p62
Rails 5.1.7

  • Answer # 1

    When using keyword for loop argument, with_index cannot be used? When
    companies.each.with_index (1) do | hash, rank |And use it with hash [: company], or do rank.succ using nogly each.

    Is it not usable? I thought
    each.with_index (1) {| para | pp para} And when
    each {| para | pp para} And when
    There is no difference in the pp result. In other words, the index of with_index is not passed as a parameter.

    in the method calldef aa (a:, b:, i);pp [a, b, i];endWhat happens if I try
    SyntaxError: unexpected tIDENTIFIER def aa (a:, b:, i);pp [a, b, i];end                         ^
    In ruby ​​2.6.1p33, it seems that normal arguments cannot be added after the kieyword argument.
    That said, I thought it would be the same with the block parameter argument.