<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.1.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Rubyize this</title>
	<link>http://www.rubyfleebie.com/rubyize-this/</link>
	<description>Because programming should be fun</description>
	<pubDate>Sat, 22 Nov 2008 05:32:52 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>

	<item>
		<title>By: Gerry</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-271</link>
		<author>Gerry</author>
		<pubDate>Mon, 25 Jun 2007 04:41:30 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-271</guid>
					<description>Here is an alternative to get the idea rolling.
&lt;pre&gt;
def manage_ducks(ducks)
  if ducks.nil? &#124;&#124; !ducks.won_stanley_cup?
    ducks = fetch_some_champions
  end
  ducks.beat_random_opponent
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Here is an alternative to get the idea rolling.</p>
<pre>
def manage_ducks(ducks)
  if ducks.nil? || !ducks.won_stanley_cup?
    ducks = fetch_some_champions
  end
  ducks.beat_random_opponent
end
</pre>
]]></content:encoded>
				</item>
	<item>
		<title>By: Gerry</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-272</link>
		<author>Gerry</author>
		<pubDate>Mon, 25 Jun 2007 04:42:40 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-272</guid>
					<description>it doesn't appear that wrapping in  tags works.</description>
		<content:encoded><![CDATA[<p>it doesn&#8217;t appear that wrapping in  tags works.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Alpha Chen</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-273</link>
		<author>Alpha Chen</author>
		<pubDate>Mon, 25 Jun 2007 05:02:29 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-273</guid>
					<description>ducks = fetch_some_champions unless ducks and ducks.won_stanley_cup?
ducks.beat_random_opponent</description>
		<content:encoded><![CDATA[<p>ducks = fetch_some_champions unless ducks and ducks.won_stanley_cup?<br />
ducks.beat_random_opponent</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Jbosss</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-274</link>
		<author>Jbosss</author>
		<pubDate>Mon, 25 Jun 2007 11:13:07 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-274</guid>
					<description>The code is ugly indeed. I agree with Aplha Chen's suggestion, its the same I have came up with. Pretty and still nice and readable.</description>
		<content:encoded><![CDATA[<p>The code is ugly indeed. I agree with Aplha Chen&#8217;s suggestion, its the same I have came up with. Pretty and still nice and readable.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Nando Vieira</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-275</link>
		<author>Nando Vieira</author>
		<pubDate>Mon, 25 Jun 2007 12:15:21 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-275</guid>
					<description>Here it is:
&lt;pre&gt;
def manage_ducks(ducks)
  ducks = ducks.fetch_some_champions unless ducks.nil? &#124;&#124; ducks.won_stanley_cup?
  ducks.beat_random_opponent
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Here it is:</p>
<pre>
def manage_ducks(ducks)
  ducks = ducks.fetch_some_champions unless ducks.nil? || ducks.won_stanley_cup?
  ducks.beat_random_opponent
end
</pre>
]]></content:encoded>
				</item>
	<item>
		<title>By: Casey Winans</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-276</link>
		<author>Casey Winans</author>
		<pubDate>Mon, 25 Jun 2007 12:52:11 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-276</guid>
					<description>&lt;pre&gt;def manage_ducks(ducks)
  ducks = fetch_some_champions if ducks.nil? &#124;&#124; !ducks.won_stanley_cup?
  ducks.beat_random_opponent
end&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<pre>def manage_ducks(ducks)
  ducks = fetch_some_champions if ducks.nil? || !ducks.won_stanley_cup?
  ducks.beat_random_opponent
end</pre>
]]></content:encoded>
				</item>
	<item>
		<title>By: Silvio Fonseca</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-277</link>
		<author>Silvio Fonseca</author>
		<pubDate>Mon, 25 Jun 2007 13:06:40 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-277</guid>
					<description>Nando and Alpha Chen solutions were exactly what I had in mind. IMHO, Nando's solutions is a bit better, using the "nil?" method, which is easier to understand. Just a minor correction on the logic:

&lt;pre&gt;def manage_ducks(ducks)
  ducks = ducks.fetch_some_champions &lt;b&gt;if&lt;/b&gt; ducks.nil? &#124;&#124; !ducks.won_stanley_cup?
  ducks.beat_random_opponent
end&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Nando and Alpha Chen solutions were exactly what I had in mind. IMHO, Nando&#8217;s solutions is a bit better, using the &#8220;nil?&#8221; method, which is easier to understand. Just a minor correction on the logic:</p>
<pre>def manage_ducks(ducks)
  ducks = ducks.fetch_some_champions <b>if</b> ducks.nil? || !ducks.won_stanley_cup?
  ducks.beat_random_opponent
end</pre>
]]></content:encoded>
				</item>
	<item>
		<title>By: RSL</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-278</link>
		<author>RSL</author>
		<pubDate>Mon, 25 Jun 2007 15:18:08 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-278</guid>
					<description>One thing I noticed no one was doing is taking advantage of Ruby returning an object from assignment. The whole ducks.beat_random_opponent thing can do without the ducks.

&lt;pre&gt;
# Verbose
def manage_ducks(ducks)
  unless ducks and ducks.won_stanley_cup?
    fetch_some_champions
  else
    ducks
  end.beat_random_opponent
end

# Superterse, if Perl-y
def manage_ducks(ducks)
  ((ducks &#38;&#38; ducks.won_stanley_cup?) ? ducks : fetch_some_champions).beat_random_opponent
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>One thing I noticed no one was doing is taking advantage of Ruby returning an object from assignment. The whole ducks.beat_random_opponent thing can do without the ducks.</p>
<pre>
# Verbose
def manage_ducks(ducks)
  unless ducks and ducks.won_stanley_cup?
    fetch_some_champions
  else
    ducks
  end.beat_random_opponent
end

# Superterse, if Perl-y
def manage_ducks(ducks)
  ((ducks &amp;&amp; ducks.won_stanley_cup?) ? ducks : fetch_some_champions).beat_random_opponent
end
</pre>
]]></content:encoded>
				</item>
	<item>
		<title>By: RSL</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-279</link>
		<author>RSL</author>
		<pubDate>Mon, 25 Jun 2007 15:20:02 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-279</guid>
					<description>Also, you don't have to ask "if ducks.nil?" when "if ducks" works just fine and is perfectly idiomatic Ruby.</description>
		<content:encoded><![CDATA[<p>Also, you don&#8217;t have to ask &#8220;if ducks.nil?&#8221; when &#8220;if ducks&#8221; works just fine and is perfectly idiomatic Ruby.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-280</link>
		<author>Frank</author>
		<pubDate>Mon, 25 Jun 2007 22:33:09 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-280</guid>
					<description>Thanks everyone for commenting in this first edition of Rubyize this (seeing it was quite popular there will be some more).

My favorite solution is without a doubt the one by Nando (once you remove the logic mistake like Silvio has pointed out) and Casey. In this situation I prefer the if over unless because it feels more natural. (unless ducks and ducks.won_stanley_cup? can be a bit confusing when you read it).

I'd also like to talk about RSL suggestions which I find very interesting (the second one is a bit cryptic... but still pretty nice). Although the first solution looks awkward at first, I find it extremely readable and clean. I'll try to include some of this stuff in my applications in the future.

RSL, however I don't understand your last comment. "if ducks.nil?" is definitely not the same as "if ducks". I guess you wanted to say "unless ducks".</description>
		<content:encoded><![CDATA[<p>Thanks everyone for commenting in this first edition of Rubyize this (seeing it was quite popular there will be some more).</p>
<p>My favorite solution is without a doubt the one by Nando (once you remove the logic mistake like Silvio has pointed out) and Casey. In this situation I prefer the if over unless because it feels more natural. (unless ducks and ducks.won_stanley_cup? can be a bit confusing when you read it).</p>
<p>I&#8217;d also like to talk about RSL suggestions which I find very interesting (the second one is a bit cryptic&#8230; but still pretty nice). Although the first solution looks awkward at first, I find it extremely readable and clean. I&#8217;ll try to include some of this stuff in my applications in the future.</p>
<p>RSL, however I don&#8217;t understand your last comment. &#8220;if ducks.nil?&#8221; is definitely not the same as &#8220;if ducks&#8221;. I guess you wanted to say &#8220;unless ducks&#8221;.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Nando Vieira</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-281</link>
		<author>Nando Vieira</author>
		<pubDate>Mon, 25 Jun 2007 23:14:08 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-281</guid>
					<description>Sorry... my bad! ;)
I posted it without reviewing just to be fast.. huahahuahuau. :P</description>
		<content:encoded><![CDATA[<p>Sorry&#8230; my bad! <img src='http://www.rubyfleebie.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
I posted it without reviewing just to be fast.. huahahuahuau. <img src='http://www.rubyfleebie.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /></p>
]]></content:encoded>
				</item>
	<item>
		<title>By: RSL</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-282</link>
		<author>RSL</author>
		<pubDate>Tue, 26 Jun 2007 03:24:25 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-282</guid>
					<description>Woops. You're right. I did have that backwards. I guess I shouldn't post comments [especially not ones containing _code_] before I've finished my morning coffee.</description>
		<content:encoded><![CDATA[<p>Woops. You&#8217;re right. I did have that backwards. I guess I shouldn&#8217;t post comments [especially not ones containing _code_] before I&#8217;ve finished my morning coffee.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Matt Jones</title>
		<link>http://www.rubyfleebie.com/rubyize-this/#comment-283</link>
		<author>Matt Jones</author>
		<pubDate>Thu, 28 Jun 2007 02:10:59 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/rubyize-this/#comment-283</guid>
					<description>A little late, but this is an interesting approach:


def manage_ducks(ducks)
  throw(nil) unless ducks.won_stanley_cup? rescue ducks = fetch_some_champions  
  ducks.beat_random_opponent
end


A little weird, but it works. If ducks is nil, the unless clause will throw an exception; if 
won_stanley_cup? is false, it throws a nil exception.</description>
		<content:encoded><![CDATA[<p>A little late, but this is an interesting approach:</p>
<p>def manage_ducks(ducks)<br />
  throw(nil) unless ducks.won_stanley_cup? rescue ducks = fetch_some_champions<br />
  ducks.beat_random_opponent<br />
end</p>
<p>A little weird, but it works. If ducks is nil, the unless clause will throw an exception; if<br />
won_stanley_cup? is false, it throws a nil exception.</p>
]]></content:encoded>
				</item>
</channel>
</rss>
