<?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: True, False And Nil Objects In Ruby</title> <atom:link href="http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/feed/" rel="self" type="application/rss+xml" /><link>http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/</link> <description>For the betterment of the software craft...</description> <lastBuildDate>Mon, 21 Nov 2011 13:57:06 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.2</generator> <item><title>By: Ruby: Links, News and Resources (2) &#171; Angel &#8220;Java&#8221; Lopez on Blog</title><link>http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/comment-page-1/#comment-7631</link> <dc:creator>Ruby: Links, News and Resources (2) &#171; Angel &#8220;Java&#8221; Lopez on Blog</dc:creator> <pubDate>Wed, 16 Nov 2011 09:29:21 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1174#comment-7631</guid> <description>[...] True, False And Nil Objects In Ruby http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/ [...]</description> <content:encoded><![CDATA[<p>[...] True, False And Nil Objects In Ruby <a
href="http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/" rel="nofollow">http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/</a> [...]</p> ]]></content:encoded> </item> <item><title>By: Peter</title><link>http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/comment-page-1/#comment-6738</link> <dc:creator>Peter</dc:creator> <pubDate>Mon, 13 Dec 2010 02:04:33 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1174#comment-6738</guid> <description>This also leads to some inconsistency:
&gt;&gt; nil.to_s ? true:false
=&gt; true
&gt;&gt; nil ? true:false
=&gt; false</description> <content:encoded><![CDATA[<p>This also leads to some inconsistency:</p><p>&gt;&gt; nil.to_s ? true:false<br
/> =&gt; true<br
/> &gt;&gt; nil ? true:false<br
/> =&gt; false</p> ]]></content:encoded> </item> <item><title>By: Quora</title><link>http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/comment-page-1/#comment-6670</link> <dc:creator>Quora</dc:creator> <pubDate>Sun, 14 Nov 2010 23:35:11 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1174#comment-6670</guid> <description>&lt;strong&gt;Grokking the Ruby object model...&lt;/strong&gt;
I&#039;m trying to understand the Ruby object model. Here are the best sources I&#039;ve found. I recommend reading them syntopically. That&#039;s a fancy word for &quot;read them all at the same time, not in order&quot;. But they&#039;re listed in a pretty good order too. St...</description> <content:encoded><![CDATA[<p><strong>Grokking the Ruby object model&#8230;</strong></p><p>I&#8217;m trying to understand the Ruby object model. Here are the best sources I&#8217;ve found. I recommend reading them syntopically. That&#8217;s a fancy word for &#8220;read them all at the same time, not in order&#8221;. But they&#8217;re listed in a pretty good order too. St&#8230;</p> ]]></content:encoded> </item> <item><title>By: Nil</title><link>http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/comment-page-1/#comment-6368</link> <dc:creator>Nil</dc:creator> <pubDate>Mon, 18 Oct 2010 12:22:07 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1174#comment-6368</guid> <description>You should not evaluate strings as boolean, because &quot;warning: string literal in condition&quot; and the result is always true, ant it is very likely that you do not wanted to express that. Test for emptiness!
&gt; print( (! &quot;&quot;.empty? ? &quot;true&quot; : &quot;false&quot;) + &quot;\n&quot; )
false
&gt; print( (! &quot;a&quot;.empty? ? &quot;true&quot; : &quot;false&quot;) + &quot;\n&quot; )
true</description> <content:encoded><![CDATA[<p>You should not evaluate strings as boolean, because &#8220;warning: string literal in condition&#8221; and the result is always true, ant it is very likely that you do not wanted to express that. Test for emptiness!</p><p>&gt; print( (! &#8220;&#8221;.empty? ? &#8220;true&#8221; : &#8220;false&#8221;) + &#8220;\n&#8221; )<br
/> false<br
/> &gt; print( (! &#8220;a&#8221;.empty? ? &#8220;true&#8221; : &#8220;false&#8221;) + &#8220;\n&#8221; )<br
/> true</p> ]]></content:encoded> </item> <item><title>By: Разработка на Ruby и Rails c нуля &#187; Эти загадочные True, False и Nil объекты Ruby</title><link>http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/comment-page-1/#comment-5005</link> <dc:creator>Разработка на Ruby и Rails c нуля &#187; Эти загадочные True, False и Nil объекты Ruby</dc:creator> <pubDate>Tue, 04 May 2010 17:46:26 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1174#comment-5005</guid> <description>[...] Перевод статьи  True, False And Nil Objects In Ruby [...]</description> <content:encoded><![CDATA[<p>[...] Перевод статьи  True, False And Nil Objects In Ruby [...]</p> ]]></content:encoded> </item> <item><title>By: Alan Skorkin</title><link>http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/comment-page-1/#comment-2733</link> <dc:creator>Alan Skorkin</dc:creator> <pubDate>Sat, 12 Sep 2009 03:56:28 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1174#comment-2733</guid> <description>This makes it even clearer, thanks for sharing it with everyone.</description> <content:encoded><![CDATA[<p>This makes it even clearer, thanks for sharing it with everyone.</p> ]]></content:encoded> </item> <item><title>By: Michael Edgar</title><link>http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/comment-page-1/#comment-2731</link> <dc:creator>Michael Edgar</dc:creator> <pubDate>Sat, 12 Sep 2009 00:17:00 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1174#comment-2731</guid> <description>That explanation doesn&#039;t actually explain anything.
Every object in Ruby is represented by a pointer, typedeffed as &quot;VALUE&quot; in C. Most objects, such as Arrays, Hashes, and so on, are a small struct of data in memory, which the VALUE points to. Fixnums, however, are constants and need no extra data - they&#039;re just a number, which can be represented as a VALUE. Similarly, false is a constant, true is a constant, and nil is a constant. Their values, 0, 2, and 4, are based on bitmasks. This leaves the 1 bit unused. 1 is used for fixnums - to find the VALUE for a given integer, take 1 &#124; (value &lt;&lt; 1) -- 10.object_id == 11, 4.object_id == 9, and so on. To test if a given VALUE is a fixnum constant in C, one only perform (val &amp; 1).</description> <content:encoded><![CDATA[<p>That explanation doesn&#8217;t actually explain anything.</p><p>Every object in Ruby is represented by a pointer, typedeffed as &#8220;VALUE&#8221; in C. Most objects, such as Arrays, Hashes, and so on, are a small struct of data in memory, which the VALUE points to. Fixnums, however, are constants and need no extra data &#8211; they&#8217;re just a number, which can be represented as a VALUE. Similarly, false is a constant, true is a constant, and nil is a constant. Their values, 0, 2, and 4, are based on bitmasks. This leaves the 1 bit unused. 1 is used for fixnums &#8211; to find the VALUE for a given integer, take 1 | (value &lt;&lt; 1) &#8212; 10.object_id == 11, 4.object_id == 9, and so on. To test if a given VALUE is a fixnum constant in C, one only perform (val &amp; 1).</p> ]]></content:encoded> </item> <item><title>By: Alan Skorkin</title><link>http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/comment-page-1/#comment-2726</link> <dc:creator>Alan Skorkin</dc:creator> <pubDate>Fri, 11 Sep 2009 13:02:26 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1174#comment-2726</guid> <description>I believe in not being too much of a purist. In some situations it makes sense to hack the hell out of something just to get it to work and save yourself some headache and annoyance :). If you need to you can go back to it and fix it up later.</description> <content:encoded><![CDATA[<p>I believe in not being too much of a purist. In some situations it makes sense to hack the hell out of something just to get it to work and save yourself some headache and annoyance :). If you need to you can go back to it and fix it up later.</p> ]]></content:encoded> </item> <item><title>By: Robert Lowrey</title><link>http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/comment-page-1/#comment-2722</link> <dc:creator>Robert Lowrey</dc:creator> <pubDate>Thu, 10 Sep 2009 15:21:21 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1174#comment-2722</guid> <description>While it&#039;s horribly wrong and I&#039;ll probably be flamed to death for showing this, I&#039;ve used something like this in a small script that was dealing with some data conversion issues and some date data was coming across as nil.
The String method &#039;makedate&#039; was the whole point but by adding &#039;makdate&#039; to NilClass, you can do away with nil-checking (I had several dates to check &amp; convert) and still get your desired result.
I DO NOT recommend doing this as you probably should write the code to do the nil-checking, but I was tired of all the &quot;unless yadi.nil?&quot; I was adding to my little script.
class NilClass
def makedate
Time.parse(&quot;1980-01-01 00:00:00&quot;)
end
end
class String
def makedate
begin
Time.parse(self)
rescue ArgumentError
Time.parse(&quot;1980-01-01 00:00:00&quot;)
end
end
end</description> <content:encoded><![CDATA[<p>While it&#8217;s horribly wrong and I&#8217;ll probably be flamed to death for showing this, I&#8217;ve used something like this in a small script that was dealing with some data conversion issues and some date data was coming across as nil.</p><p>The String method &#8216;makedate&#8217; was the whole point but by adding &#8216;makdate&#8217; to NilClass, you can do away with nil-checking (I had several dates to check &amp; convert) and still get your desired result.</p><p>I DO NOT recommend doing this as you probably should write the code to do the nil-checking, but I was tired of all the &#8220;unless yadi.nil?&#8221; I was adding to my little script.</p><p>class NilClass<br
/> def makedate<br
/> Time.parse(&#8220;1980-01-01 00:00:00&#8243;)<br
/> end<br
/> end</p><p>class String<br
/> def makedate<br
/> begin<br
/> Time.parse(self)<br
/> rescue ArgumentError<br
/> Time.parse(&#8220;1980-01-01 00:00:00&#8243;)<br
/> end<br
/> end<br
/> end</p> ]]></content:encoded> </item> <item><title>By: Mark Thomas</title><link>http://www.skorks.com/2009/09/true-false-and-nil-objects-in-ruby/comment-page-1/#comment-2708</link> <dc:creator>Mark Thomas</dc:creator> <pubDate>Wed, 09 Sep 2009 14:04:36 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1174#comment-2708</guid> <description>Nice, but it doesn&#039;t explain why Matz made it that way.</description> <content:encoded><![CDATA[<p>Nice, but it doesn&#8217;t explain why Matz made it that way.</p> ]]></content:encoded> </item> </channel> </rss>
