<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cashplk的心路历程 &#187; inject</title>
	<atom:link href="http://cashplk.com/tag/inject/feed/" rel="self" type="application/rss+xml" />
	<link>http://cashplk.com</link>
	<description>学无止境，梦如夏花～</description>
	<lastBuildDate>Sat, 31 Jul 2010 10:15:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>对于inject的使用</title>
		<link>http://cashplk.com/2009/05/23/%e5%af%b9%e4%ba%8einject%e7%9a%84%e4%bd%bf%e7%94%a8/</link>
		<comments>http://cashplk.com/2009/05/23/%e5%af%b9%e4%ba%8einject%e7%9a%84%e4%bd%bf%e7%94%a8/#comments</comments>
		<pubDate>Sat, 23 May 2009 04:28:17 +0000</pubDate>
		<dc:creator>cashplk</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Alex]]></category>
		<category><![CDATA[inject]]></category>

		<guid isPermaLink="false">http://cashplk.com/?p=6</guid>
		<description><![CDATA[看到Alex的Alex学Ruby[ inject需要注意的地方 ] ，节选部分如下： inject([]) do &#124;item ,i &#124;这样的写法，每一步，item都会被设置为block的返回值。 如下： 1 2 3 4 5 6 7 8 9 arr1 = &#91;&#93; arr2 = &#91;1,2,3&#93; &#160; arr2.each do &#124;i&#124; arr1 &#60;&#60; i+1 end &#160; p arr1 #=&#62; [2, 3, 4] 使用inject，则可以写为： 1 2 3 4 5 6 7 8 arr2 = &#91;1,2,3&#93; &#160; arr = [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: x-small;"> </span><span style="font-size: x-small;">看到<a title="Alex" href="http://blackanger.blog.51cto.com/" target="_blank">Alex</a>的<a title="Alex学Ruby[ inject需要注意的地方 ]" href="http://blackanger.blog.51cto.com/140924/90539" target="_blank">Alex学Ruby[ inject需要注意的地方 ]</a> ，节选部分如下：<br />
</span><span style="font-size: x-small;"><br />
</span><span style="font-size: x-small;"> </span><span style="font-size: x-small;">inject([]) do |item ,i |这样的写法，每一步，item都会被设置为block的返回值。</span></p>
<p>如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">    arr1 = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    arr2 = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span>,<span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>  
&nbsp;
    arr2.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span>
        arr1 <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>  i<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006666;">1</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#CC0066; font-weight:bold;">p</span> arr1
    <span style="color:#008000; font-style:italic;">#=&gt; [2, 3, 4]</span></pre></td></tr></table></div>

<p>使用inject，则可以写为：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">    arr2 = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span>,<span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
    arr = arr2.<span style="color:#9900CC;">inject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span><span style="color:#006600; font-weight:bold;">|</span>arr1, i<span style="color:#006600; font-weight:bold;">|</span>
        arr1 <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> i <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1</span> 
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
     <span style="color:#CC0066; font-weight:bold;">p</span> arr1
     <span style="color:#008000; font-style:italic;">#=&gt;[2,3,4]</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://cashplk.com/2009/05/23/%e5%af%b9%e4%ba%8einject%e7%9a%84%e4%bd%bf%e7%94%a8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->