<?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://khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/feed/" rel="self" type="application/rss+xml" />
	<link>http://khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/</link>
	<description>Cool Web Development...</description>
	<lastBuildDate>Wed, 08 Feb 2012 19:11:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: antan</title>
		<link>http://khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-35091</link>
		<dc:creator>antan</dc:creator>
		<pubDate>Sun, 11 Sep 2011 08:36:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-35091</guid>
		<description>I think this is what happens:

b=5 #&lt;= b points to an object 5

def test(a) #&lt;= a points to the same object as b (5)
  a=6 #&lt;= a points to a new object 6
end

test(b) #&lt;= returns 5

----------------------------
b=[1,2,3]

def test2(a) #&lt;= a points to the same object as b ([1,2,3])
  a[0]=6 #&lt;= a[0], which pointed to the first object in the array (1), now points to the new object 6
end

test2(b) #&lt;= returns [6,2,3]</description>
		<content:encoded><![CDATA[<p>I think this is what happens:</p>
<p>b=5 #&lt;= b points to an object 5</p>
<p>def test(a) #&lt;= a points to the same object as b (5)<br />
  a=6 #&lt;= a points to a new object 6<br />
end</p>
<p>test(b) #&lt;= returns 5</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
b=[1,2,3]</p>
<p>def test2(a) #&lt;= a points to the same object as b ([1,2,3])<br />
  a[0]=6 #&lt;= a[0], which pointed to the first object in the array (1), now points to the new object 6<br />
end</p>
<p>test2(b) #&lt;= returns [6,2,3]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Black_crown</title>
		<link>http://khelll.com/blog/ruby/ruby-pass-by-value-or-by-reference/comment-page-1/#comment-20809</link>
		<dc:creator>Black_crown</dc:creator>
		<pubDate>Fri, 25 Mar 2011 11:00:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=303#comment-20809</guid>
		<description>As i read above ...my curiosity asking a question to me.May be its stupid but i dare to ask to you.i am a newbie to ruby with strong background of .net, i found some new in ruby which is not possible in some other as i know. so  here the question is
i defined a method  which taking one parameter ,

def dummy_method(valued)
 some_thing=valued
return some_thing
end

now on the call of this method 
 dummy_method(valued=gets.chomp.to_i)  #that is a normal call

 but can i do like this to call

dummy_method(valued= print &quot; Enter your value&quot; ,gets.chomp.to_i)</description>
		<content:encoded><![CDATA[<p>As i read above &#8230;my curiosity asking a question to me.May be its stupid but i dare to ask to you.i am a newbie to ruby with strong background of .net, i found some new in ruby which is not possible in some other as i know. so  here the question is<br />
i defined a method  which taking one parameter ,</p>
<p>def dummy_method(valued)<br />
 some_thing=valued<br />
return some_thing<br />
end</p>
<p>now on the call of this method<br />
 dummy_method(valued=gets.chomp.to_i)  #that is a normal call</p>
<p> but can i do like this to call</p>
<p>dummy_method(valued= print &#8221; Enter your value&#8221; ,gets.chomp.to_i)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khelll</title>
		<link>http://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://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://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://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://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://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://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://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>
</channel>
</rss>

