好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

ruby doc

ruby doc

method


http://apidock测试数据/ruby/Enumerable/each_with_index




each_with_index

Ruby latest stable (v1_8_7_72) - 0 notes - Class: Enumerable

1_8_6_287 (0) 1_8_7_72 (-38) What's this?

Related methods

Instance methods (45) all? any? collect count cycle detect drop drop_while each_cons each_slice each_with_index entries enum_cons enum_slice enum_with_index find find_all find_index first grep group_by include? inject map max max_by member? min min_by minmax minmax_by none? one? partition reduce reject reverse_each select sort sort_by take take_while to_a to_set zip

= private
= protected

each_with_index () public

Calls block with two arguments, the item and its index, for each item in enum .

   <span class="ident">hash</span> <span class="punct">=</span> <span class="constant"><a href="http://apidock测试数据/ruby/Hash">Hash</a></span><span class="punct">.</span><span class="ident">new</span>
   <span class="punct">%w(</span><span class="string">cat dog wombat</span><span class="punct">).</span><span class="ident"><a href="http://apidock测试数据/ruby/Enumerable/each_with_index">each_with_index</a></span> <span class="punct">{|</span><span class="ident">item</span><span class="punct">,</span> <span class="ident">index</span><span class="punct">|</span>
     <span class="ident">hash</span><span class="punct">[</span><span class="ident">item</span><span class="punct">]</span> <span class="punct">=</span> <span class="ident">index</span>
   <span class="punct">}</span>
   <span class="ident">hash</span>   <span class="comment">#=> {"cat"=>0, "wombat"=>2, "dog"=>1}</span>



查看更多关于ruby doc的详细内容...

  阅读:36次

上一篇: 网店系统

下一篇:rails3 bundle introduce