<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>exuxu (exuxu)</title>
    <link>https://ruby-china.org/exuxu</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>一个 关于 each_with_index 函数问题 </title>
      <description>&lt;p&gt;#data&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@a = ["2","0","3"]
@b = ["a","b","c"]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;#result，过滤掉 a 中值为 0 的元素，结果如下&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@c = {"a"=&amp;gt;"2", "c"=&amp;gt;"3"}

        @b.each_with_index do |value, index|
                @c[value] = @a[index]
        end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这样可以可以获取所有的结果而无法过滤。&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@b.each_with_index do |value, index|
  if @a[index] &amp;gt; 0
    @c[value] = @a[index]
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;或者&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@b.each_with_index do |value, index|
  @c[value] = @a[index]  if a[index] &amp;gt; 0
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;都么有效果，是为什么呢？&lt;/p&gt;</description>
      <author>exuxu</author>
      <pubDate>Wed, 19 Aug 2015 15:23:13 +0800</pubDate>
      <link>https://ruby-china.org/topics/26983</link>
      <guid>https://ruby-china.org/topics/26983</guid>
    </item>
  </channel>
</rss>
