<?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"
	>
<channel>
	<title>Comments on: Ruby Gotcha&#8212;Private Assignment Methods not so Private</title>
	<atom:link href="http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/</link>
	<description>Politics, Programming and Possibilities</description>
	<pubDate>Wed, 07 Jan 2009 14:14:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Jacob Atzen</title>
		<link>http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1488</link>
		<dc:creator>Jacob Atzen</dc:creator>
		<pubDate>Sat, 06 Jan 2007 14:11:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1488</guid>
		<description>Duane asked:

Why shouldn’t we have to declare “l=” as a public method (or at the least, a protected method) so that “m=” can call “self.l=”?

I'm no Ruby guru, but my guess is that then we'd have no way of creating private assignment methods, maybe that's what "they" are trying to tell us ;-) I agree that it's a weird exception though I don't know how it could be made any more elegant with the current Ruby syntax.</description>
		<content:encoded><![CDATA[<p>Duane asked:</p>
<p>Why shouldn’t we have to declare “l=” as a public method (or at the least, a protected method) so that “m=” can call “self.l=”?</p>
<p>I&#8217;m no Ruby guru, but my guess is that then we&#8217;d have no way of creating private assignment methods, maybe that&#8217;s what &#8220;they&#8221; are trying to tell us <img src='http://blog.inquirylabs.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> I agree that it&#8217;s a weird exception though I don&#8217;t know how it could be made any more elegant with the current Ruby syntax.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Duane Johnson</title>
		<link>http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1450</link>
		<dc:creator>Duane Johnson</dc:creator>
		<pubDate>Thu, 04 Jan 2007 22:59:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1450</guid>
		<description>Jacob:

My mistake.  "def m; l; end" does work.  I was pointing you in the wrong direction. :)

I'm kind of following you at this point, but maybe you could expound a bit on this particular aspect of the "discrepency":

&lt;code&gt;&lt;pre&gt;
class T
  private
  def l=(val); puts val end

  public
  # I would think that "l=" needs to be
  # 'protected' for this to work:
  def m=(val); self.l=(val) end
end
&lt;/pre&gt;&lt;/code&gt;

Now suppose t = T.new:

&lt;code&gt;&lt;pre&gt;
t.l = 1
# =&gt; NoMethodError: private method `l=' called for #&lt;T:0x6e26c&gt;

t.m = 1
# =&gt; 1
&lt;/pre&gt;&lt;/code&gt;

If I understand you correctly, you're saying this is an anomaly that Ruby intentionally affords us... but why?  Why shouldn't we have to declare "l=" as a public method (or at the least, a protected method) so that "m=" can call "self.l="?

It just seems like a weird exception to the rules to me.  But obviously that's the way it is, so I'll adjust :)</description>
		<content:encoded><![CDATA[<p>Jacob:</p>
<p>My mistake.  &#8220;def m; l; end&#8221; does work.  I was pointing you in the wrong direction. <img src='http://blog.inquirylabs.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;m kind of following you at this point, but maybe you could expound a bit on this particular aspect of the &#8220;discrepency&#8221;:</p>
<p><code>
<pre>
class T
  private
  def l=(val); puts val end

  public
  # I would think that "l=" needs to be
  # 'protected' for this to work:
  def m=(val); self.l=(val) end
end
</pre>
<p></code></p>
<p>Now suppose t = T.new:</p>
<p><code>
<pre>
t.l = 1
# => NoMethodError: private method `l=' called for #<t :0x6e26c>

t.m = 1
# => 1
</t></pre>
<p></code></p>
<p>If I understand you correctly, you&#8217;re saying this is an anomaly that Ruby intentionally affords us&#8230; but why?  Why shouldn&#8217;t we have to declare &#8220;l=&#8221; as a public method (or at the least, a protected method) so that &#8220;m=&#8221; can call &#8220;self.l=&#8221;?</p>
<p>It just seems like a weird exception to the rules to me.  But obviously that&#8217;s the way it is, so I&#8217;ll adjust <img src='http://blog.inquirylabs.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Atzen</title>
		<link>http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1449</link>
		<dc:creator>Jacob Atzen</dc:creator>
		<pubDate>Thu, 04 Jan 2007 22:42:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1449</guid>
		<description>I'm with Tobi on this one, his code works for me. The discrepency is due to the fact that assignment needs a receiver otherwise it's just assignment to a local variable.

Say you have "def m=(val); l = val; end" then the l variable is simply a local variable, to make it into a method call we need the receiver (self).

Now usually you wouldn't be able to call a private method with an explicit reciever but with assignment Ruby goes out of it's way to make sure you can.</description>
		<content:encoded><![CDATA[<p>I&#8217;m with Tobi on this one, his code works for me. The discrepency is due to the fact that assignment needs a receiver otherwise it&#8217;s just assignment to a local variable.</p>
<p>Say you have &#8220;def m=(val); l = val; end&#8221; then the l variable is simply a local variable, to make it into a method call we need the receiver (self).</p>
<p>Now usually you wouldn&#8217;t be able to call a private method with an explicit reciever but with assignment Ruby goes out of it&#8217;s way to make sure you can.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Duane Johnson</title>
		<link>http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1447</link>
		<dc:creator>Duane Johnson</dc:creator>
		<pubDate>Thu, 04 Jan 2007 22:27:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1447</guid>
		<description>tobi: Perhaps I should have named my post, "self referenced private method is inaccessible" or something to that effect.

The 'def m; l; end' suggestion you have there is precisely what I expected to work, which does *not* work.</description>
		<content:encoded><![CDATA[<p>tobi: Perhaps I should have named my post, &#8220;self referenced private method is inaccessible&#8221; or something to that effect.</p>
<p>The &#8216;def m; l; end&#8217; suggestion you have there is precisely what I expected to work, which does *not* work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Hodos</title>
		<link>http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1443</link>
		<dc:creator>Dan Hodos</dc:creator>
		<pubDate>Thu, 04 Jan 2007 21:34:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1443</guid>
		<description>Actually, I think I didn't answer your question. Please disregard!</description>
		<content:encoded><![CDATA[<p>Actually, I think I didn&#8217;t answer your question. Please disregard!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Hodos</title>
		<link>http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1442</link>
		<dc:creator>Dan Hodos</dc:creator>
		<pubDate>Thu, 04 Jan 2007 21:27:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1442</guid>
		<description>Turns out private methods, by definition, *cannot* have an explicit receiver. Regardless of whether you're calling it from a place that's technically "in scope."</description>
		<content:encoded><![CDATA[<p>Turns out private methods, by definition, *cannot* have an explicit receiver. Regardless of whether you&#8217;re calling it from a place that&#8217;s technically &#8220;in scope.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tobi</title>
		<link>http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1441</link>
		<dc:creator>tobi</dc:creator>
		<pubDate>Thu, 04 Jan 2007 21:16:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.inquirylabs.com/2007/01/04/ruby-gotcha-private-assignment-methods-not-so-private/#comment-1441</guid>
		<description>Self references the current object. There is no magic to that. Its the same as an instance variable pointing to the object. Everything you call on self goes through the public interface of the object. 

def m; l; end should work</description>
		<content:encoded><![CDATA[<p>Self references the current object. There is no magic to that. Its the same as an instance variable pointing to the object. Everything you call on self goes through the public interface of the object. </p>
<p>def m; l; end should work</p>
]]></content:encoded>
	</item>
</channel>
</rss>
