<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Ruby, pass by value or by reference?</title>
	<atom:link href="http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/</link>
	<description>What web development means....</description>
	<lastBuildDate>Tue, 13 Jul 2010 05:39:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: khelll</title>
		<link>http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-4717</link>
		<dc:creator>khelll</dc:creator>
		<pubDate>Thu, 05 Nov 2009 23:23:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-4717</guid>
		<description>@taelor, I tried the following statement on Ruby 1.8.6
&lt;pre lang=&quot;RUBY&quot;&gt;
{ :some_id =&gt; 1, :something =&gt; &#039;one&#039; }.reject{&#124;k, v&#124; k =~ /_id/ }
#=&gt; {:some_id=&gt;1, :something=&gt;&quot;one&quot;}
&lt;/pre&gt;
Which is totally different from Ruby 1.9.1
&lt;pre lang=&quot;RUBY&quot;&gt;
{ :some_id =&gt; 1, :something =&gt; &#039;one&#039; }.reject{&#124;k, v&#124; k =~ /_id/ }
#=&gt; {:something=&gt;&quot;one&quot;}
&lt;/pre&gt;

If you just make it &lt;code&gt;k.to_s&lt;/code&gt;, your gist will give the same result on both versions of Ruby.
On the other hand, I can&#039;t see where pass by reference is taking place.... can you elaborate?</description>
		<content:encoded><![CDATA[<p>@taelor, I tried the following statement on Ruby 1.8.6</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:some_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:something</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'one'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">reject</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>k, v<span style="color:#006600; font-weight:bold;">|</span> k =~ <span style="color:#006600; font-weight:bold;">/</span>_id<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;">#=&gt; {:some_id=&gt;1, :something=&gt;&quot;one&quot;}</span></pre></div></div>

<p>Which is totally different from Ruby 1.9.1</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:some_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:something</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'one'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">reject</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>k, v<span style="color:#006600; font-weight:bold;">|</span> k =~ <span style="color:#006600; font-weight:bold;">/</span>_id<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;">#=&gt; {:something=&gt;&quot;one&quot;}</span></pre></div></div>

<p>If you just make it <code>k.to_s</code>, your gist will give the same result on both versions of Ruby.<br />
On the other hand, I can&#8217;t see where pass by reference is taking place&#8230;. can you elaborate?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: taelor</title>
		<link>http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-4686</link>
		<dc:creator>taelor</dc:creator>
		<pubDate>Wed, 04 Nov 2009 02:27:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-4686</guid>
		<description>Hey, khell, its been awhile since I visited your site. Just wanted to show you something along these lines of pass-by-x. check out this gist and run it in ruby 1.8.7 vs 1.9.1, you get totally different outputs. I think that the 1.9 is pass by reference in this case. 

http://gist.github.com/225709</description>
		<content:encoded><![CDATA[<p>Hey, khell, its been awhile since I visited your site. Just wanted to show you something along these lines of pass-by-x. check out this gist and run it in ruby 1.8.7 vs 1.9.1, you get totally different outputs. I think that the 1.9 is pass by reference in this case. </p>
<p><a href="http://gist.github.com/225709" rel="nofollow">http://gist.github.com/225709</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AndrewBoldman</title>
		<link>http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-2203</link>
		<dc:creator>AndrewBoldman</dc:creator>
		<pubDate>Thu, 04 Jun 2009 13:26:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-2203</guid>
		<description>Hi, cool post. I have been wondering about this topic,so thanks for writing.</description>
		<content:encoded><![CDATA[<p>Hi, cool post. I have been wondering about this topic,so thanks for writing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ennuyer.net &#187; Blog Archive &#187; I am way behind on my rails link blogging. Link dump and reboot.</title>
		<link>http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-1968</link>
		<dc:creator>Ennuyer.net &#187; Blog Archive &#187; I am way behind on my rails link blogging. Link dump and reboot.</dc:creator>
		<pubDate>Sat, 09 May 2009 10:45:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-1968</guid>
		<description>[...]  Ruby, pass by value or by reference? - Khaled alHabacheâ€™s official blog  [...]</description>
		<content:encoded><![CDATA[<p>[...]  Ruby, pass by value or by reference? &#8211; Khaled alHabacheâ€™s official blog  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khelll</title>
		<link>http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-1657</link>
		<dc:creator>khelll</dc:creator>
		<pubDate>Wed, 22 Apr 2009 19:21:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-1657</guid>
		<description>@kadom, what is being passed is a value of a copied reference, that&#039;s called pass by reference value or pass by value simply.</description>
		<content:encoded><![CDATA[<p>@kadom, what is being passed is a value of a copied reference, that&#8217;s called pass by reference value or pass by value simply.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kadom</title>
		<link>http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-1656</link>
		<dc:creator>Kadom</dc:creator>
		<pubDate>Wed, 22 Apr 2009 19:03:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-1656</guid>
		<description>bar = &quot;if you can read this bar was passed by value&quot;

def foo(bar)
  bar.replace  &quot;if you can see this, bar was passed by value reference&quot;
end

foo(bar)

puts bar

Saying that b is passed by value is as incorrect as saying that b is passed by reference.  I am able to change bar via the parameter bar.  That means that I do have a reference to bar in some sense.  If what i received was simply a value copy, then I would not be able to reach the outer scope bar.  if it was an actual pointer to bar, then I would be able to simply manipulate it as I do in C/C++.  I understand the argument about the object_id, but claiming ruby is simply pass by value misses an important distinction.  I was able to alter bar within foo when bar was passed as a parameter.</description>
		<content:encoded><![CDATA[<p>bar = &#8220;if you can read this bar was passed by value&#8221;</p>
<p>def foo(bar)<br />
  bar.replace  &#8220;if you can see this, bar was passed by value reference&#8221;<br />
end</p>
<p>foo(bar)</p>
<p>puts bar</p>
<p>Saying that b is passed by value is as incorrect as saying that b is passed by reference.  I am able to change bar via the parameter bar.  That means that I do have a reference to bar in some sense.  If what i received was simply a value copy, then I would not be able to reach the outer scope bar.  if it was an actual pointer to bar, then I would be able to simply manipulate it as I do in C/C++.  I understand the argument about the object_id, but claiming ruby is simply pass by value misses an important distinction.  I was able to alter bar within foo when bar was passed as a parameter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khelll</title>
		<link>http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-1631</link>
		<dc:creator>khelll</dc:creator>
		<pubDate>Wed, 22 Apr 2009 08:24:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-1631</guid>
		<description>&lt;strong&gt;Update:&lt;/strong&gt;
I have blogged a &lt;a href=&quot;http://www.khelll.com/blog/ruby/c-passes-by-reference-java-and-ruby-dont/&quot; rel=&quot;nofollow&quot;&gt;new article&lt;/a&gt; explaining passing by reference and value in 3 languages c++, java and ruby</description>
		<content:encoded><![CDATA[<p><strong>Update:</strong><br />
I have blogged a <a href="http://www.khelll.com/blog/ruby/c-passes-by-reference-java-and-ruby-dont/" rel="nofollow">new article</a> explaining passing by reference and value in 3 languages c++, java and ruby</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C++ passes by reference, Java and Ruby don&#8217;t - Khaled alHabache&#8217;s official blog</title>
		<link>http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-1629</link>
		<dc:creator>C++ passes by reference, Java and Ruby don&#8217;t - Khaled alHabache&#8217;s official blog</dc:creator>
		<pubDate>Wed, 22 Apr 2009 08:17:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-1629</guid>
		<description>[...] got a lot of comments for the previous article, that was explaining how Ruby passes by value, just like Java [...]</description>
		<content:encoded><![CDATA[<p>[...] got a lot of comments for the previous article, that was explaining how Ruby passes by value, just like Java [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jds</title>
		<link>http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-1628</link>
		<dc:creator>jds</dc:creator>
		<pubDate>Wed, 22 Apr 2009 08:06:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-1628</guid>
		<description>@Diego

All your gist does is prove that you can manipulate an &lt;strong&gt;object&lt;/code&gt; when passing said object as a parameter to a method.  It &lt;strong&gt;does not&lt;/strong&gt; change what the variable &lt;i&gt;object&lt;/i&gt; points to.  Look up (pass/call)-by-reference on wikipedia, and perhaps you will get a better idea of what pass-by-reference means.  When you understand what it means, then perhaps we can argue about whether or not Ruby supports it.

If Ruby supported pass-by-reference then this could work:

&lt;code&gt;
  def swap(a,b)
    a,b = b,a
  end
  foo = 1
  bar = 2
  # notice that we are not capturing a return value because we
  # wouldn&#039;t need to if Ruby used pass-by-reference.
  swap(foo,bar)  
  puts foo  # 2
  puts bar  # 1
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>@Diego</p>
<p>All your gist does is prove that you can manipulate an <strong>object when passing said object as a parameter to a method.  It </strong><strong>does not</strong> change what the variable <i>object</i> points to.  Look up (pass/call)-by-reference on wikipedia, and perhaps you will get a better idea of what pass-by-reference means.  When you understand what it means, then perhaps we can argue about whether or not Ruby supports it.</p>
<p>If Ruby supported pass-by-reference then this could work:</p>
<p><code><br />
  def swap(a,b)<br />
    a,b = b,a<br />
  end<br />
  foo = 1<br />
  bar = 2<br />
  # notice that we are not capturing a return value because we<br />
  # wouldn't need to if Ruby used pass-by-reference.<br />
  swap(foo,bar)<br />
  puts foo  # 2<br />
  puts bar  # 1<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khelll</title>
		<link>http://www.khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-1619</link>
		<dc:creator>khelll</dc:creator>
		<pubDate>Tue, 21 Apr 2009 19:49:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-1619</guid>
		<description>@ scott, what is your point?</description>
		<content:encoded><![CDATA[<p>@ scott, what is your point?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
