<?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 Quirks</title>
	<atom:link href="http://rubylearning.com/blog/2007/04/11/ruby-quirks/feed/" rel="self" type="application/rss+xml" />
	<link>http://rubylearning.com/blog/2007/04/11/ruby-quirks/</link>
	<description>Helping Ruby Programmers become Awesome</description>
	<lastBuildDate>Wed, 08 Feb 2012 15:25:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Dale Thatcher</title>
		<link>http://rubylearning.com/blog/2007/04/11/ruby-quirks/comment-page-1/#comment-18890</link>
		<dc:creator>Dale Thatcher</dc:creator>
		<pubDate>Sat, 10 Nov 2007 09:08:08 +0000</pubDate>
		<guid isPermaLink="false">http://rubylearning.com/blog/2007/04/11/ruby-quirks/#comment-18890</guid>
		<description>Slight reformat of the solution in comment 9.

expand = true if expand.nil?

As long as you&#039;re happy to use nil as not set then it should be fine.</description>
		<content:encoded><![CDATA[<p>Slight reformat of the solution in comment 9.</p>
<p>expand = true if expand.nil?</p>
<p>As long as you&#8217;re happy to use nil as not set then it should be fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ronald Fischer</title>
		<link>http://rubylearning.com/blog/2007/04/11/ruby-quirks/comment-page-1/#comment-2326</link>
		<dc:creator>Ronald Fischer</dc:creator>
		<pubDate>Tue, 26 Jun 2007 15:06:28 +0000</pubDate>
		<guid isPermaLink="false">http://rubylearning.com/blog/2007/04/11/ruby-quirks/#comment-2326</guid>
		<description>My comment is on item 6 :

This is not a bug, but desired behaviour. In your example, the variable named &#039;expand&#039; gets defined because the compiler, when parsing the statement, sees it on the lhs of an assignment operator. Being defined has nothing to do with the dynamic behaviour of the program. Even in the case

if false
expand=1
end

the variable &#039;expand&#039; would be defined.</description>
		<content:encoded><![CDATA[<p>My comment is on item 6 :</p>
<p>This is not a bug, but desired behaviour. In your example, the variable named &#8216;expand&#8217; gets defined because the compiler, when parsing the statement, sees it on the lhs of an assignment operator. Being defined has nothing to do with the dynamic behaviour of the program. Even in the case</p>
<p>if false<br />
expand=1<br />
end</p>
<p>the variable &#8216;expand&#8217; would be defined.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rhubarb</title>
		<link>http://rubylearning.com/blog/2007/04/11/ruby-quirks/comment-page-1/#comment-1123</link>
		<dc:creator>rhubarb</dc:creator>
		<pubDate>Sat, 12 May 2007 09:33:40 +0000</pubDate>
		<guid isPermaLink="false">http://rubylearning.com/blog/2007/04/11/ruby-quirks/#comment-1123</guid>
		<description>Your example in quirk 5 seems to contradict the statement of the quirk.

By calling 
  d.increase_n

you prove the statement that &quot;...But if a method uses one, and that method is available to subclasses, then it will still use the variable&quot; because increase_n is defined in the superclass C and does actually increment n. Fari enough.

But when you call 
  d.show_n

it shows that the method show_n in D can directly access n in its superlcass, when it calls 
   puts &quot;n is #{@n}&quot;

I mean if n had an attr_accessor and you referred to it directly then show_n could access it (with just n not @n) and it would make sense - since it would be a method call.

But here show_n is directly accessing the instance field n in C with no use of an inherited method.

It looks to me like that @n _is_ effectively inherited. Or unless I&#039;m misunderstanding inherited - another way of saying it is that @n is behaving like a protected field in Java.

I say protected, not public, because while any method in D can get and set @n, you can&#039;t do 
   d.n = 100    #NoMethodError: undefined method `n=&#039; for...
on the object.

Note that this direct setting restriction doesn&#039;t affect the inherited/not-inherited argument either way though, because I can&#039;t do this either

  c = C.new
  c.n = 100     #NoMethodError: undefined method `n=&#039; for

What I really want to say is: Where&#039;s the quirk here? I&#039;m sure its there but I&#039;m missing it.</description>
		<content:encoded><![CDATA[<p>Your example in quirk 5 seems to contradict the statement of the quirk.</p>
<p>By calling<br />
  d.increase_n</p>
<p>you prove the statement that &#8220;&#8230;But if a method uses one, and that method is available to subclasses, then it will still use the variable&#8221; because increase_n is defined in the superclass C and does actually increment n. Fari enough.</p>
<p>But when you call<br />
  d.show_n</p>
<p>it shows that the method show_n in D can directly access n in its superlcass, when it calls<br />
   puts &#8220;n is #{@n}&#8221;</p>
<p>I mean if n had an attr_accessor and you referred to it directly then show_n could access it (with just n not @n) and it would make sense &#8211; since it would be a method call.</p>
<p>But here show_n is directly accessing the instance field n in C with no use of an inherited method.</p>
<p>It looks to me like that @n _is_ effectively inherited. Or unless I&#8217;m misunderstanding inherited &#8211; another way of saying it is that @n is behaving like a protected field in Java.</p>
<p>I say protected, not public, because while any method in D can get and set @n, you can&#8217;t do<br />
   d.n = 100    #NoMethodError: undefined method `n=&#8217; for&#8230;<br />
on the object.</p>
<p>Note that this direct setting restriction doesn&#8217;t affect the inherited/not-inherited argument either way though, because I can&#8217;t do this either</p>
<p>  c = C.new<br />
  c.n = 100     #NoMethodError: undefined method `n=&#8217; for</p>
<p>What I really want to say is: Where&#8217;s the quirk here? I&#8217;m sure its there but I&#8217;m missing it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anthony Eden</title>
		<link>http://rubylearning.com/blog/2007/04/11/ruby-quirks/comment-page-1/#comment-719</link>
		<dc:creator>Anthony Eden</dc:creator>
		<pubDate>Fri, 20 Apr 2007 05:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://rubylearning.com/blog/2007/04/11/ruby-quirks/#comment-719</guid>
		<description>Morgan,

How about this:

expand = (expand.nil? ? true : expand)</description>
		<content:encoded><![CDATA[<p>Morgan,</p>
<p>How about this:</p>
<p>expand = (expand.nil? ? true : expand)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morgan Schweers</title>
		<link>http://rubylearning.com/blog/2007/04/11/ruby-quirks/comment-page-1/#comment-684</link>
		<dc:creator>Morgan Schweers</dc:creator>
		<pubDate>Mon, 16 Apr 2007 03:41:36 +0000</pubDate>
		<guid isPermaLink="false">http://rubylearning.com/blog/2007/04/11/ruby-quirks/#comment-684</guid>
		<description>Greetings,
Sadly that doesn&#039;t work if someone has explicitly passed in &#039;false&#039; as the value.

That&#039;s where the frustration comes in...

--  Morgan</description>
		<content:encoded><![CDATA[<p>Greetings,<br />
Sadly that doesn&#8217;t work if someone has explicitly passed in &#8216;false&#8217; as the value.</p>
<p>That&#8217;s where the frustration comes in&#8230;</p>
<p>&#8211;  Morgan</p>
]]></content:encoded>
	</item>
</channel>
</rss>

