<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nealenssle.com &#187; ruby</title>
	<atom:link href="http://nealenssle.com/blog/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://nealenssle.com/blog</link>
	<description></description>
	<lastBuildDate>Tue, 27 Sep 2011 11:39:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rocky Mountain Ruby Conf 2011</title>
		<link>http://nealenssle.com/blog/2011/09/27/rocky-mountain-ruby-conf-2011-highlights/</link>
		<comments>http://nealenssle.com/blog/2011/09/27/rocky-mountain-ruby-conf-2011-highlights/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 11:39:00 +0000</pubDate>
		<dc:creator>Neal Enssle</dc:creator>
				<category><![CDATA[untagged]]></category>
		<category><![CDATA[conferences]]></category>
		<category><![CDATA[foraker]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://nealenssle.com/blog/?p=403</guid>
		<description><![CDATA[The Foraker Labs team had a great time at this year’s Rocky Mountain Ruby Conference (#rockymtnruby). It was fantastic to see a full house at the Boulder Theatre for the two days of the conference, and we enjoyed hanging out with old friends from within the Boulder Ruby community, as well as getting a chance [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.foraker.com/">Foraker Labs</a> team had a great time at this year’s <a href="http://rockymtnruby.com">Rocky Mountain Ruby Conference</a> (#rockymtnruby). It was fantastic to see a full house at the Boulder Theatre for the two days of the conference, and we enjoyed hanging out with old friends from within the Boulder Ruby community, as well as getting a chance to meet a whole host of visitors from near and far. </p>
<p>Here’s <a href="http://www.foraker.com/rockymtnruby-2011">a brief overview of some of our favorite talks</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nealenssle.com/blog/2011/09/27/rocky-mountain-ruby-conf-2011-highlights/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to pick a random element from an Array</title>
		<link>http://nealenssle.com/blog/2011/02/28/how-to-pick-a-random-element-from-an-array/</link>
		<comments>http://nealenssle.com/blog/2011/02/28/how-to-pick-a-random-element-from-an-array/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 13:44:30 +0000</pubDate>
		<dc:creator>Neal Enssle</dc:creator>
				<category><![CDATA[untagged]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://nealenssle.com/blog/?p=391</guid>
		<description><![CDATA[Here&#8217;s a nifty little patch to Ruby&#8217;s Array class to provide a method for picking an element at random:

class Array
  def random_pick
    self.sort_by { rand }.first
  end
end

So then you can do things like this:

def what_is_your_favorite_color?
  colors = [ 'red', 'blue', 'green', 'yellow', 'purple', 'pink', 'black' ]
  colors.random_pick
end

Please don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a nifty little patch to Ruby&#8217;s Array class to provide a method for picking an element at random:</p>
<pre>
class Array
  def random_pick
    self.sort_by { rand }.first
  end
end
</pre>
<p>So then you can do things like this:</p>
<pre>
def what_is_your_favorite_color?
  colors = [ 'red', 'blue', 'green', 'yellow', 'purple', 'pink', 'black' ]
  colors.random_pick
end
</pre>
<p>Please don&#8217;t ask my why I&#8217;m doing this. The answer has something to do with test data. </p>
]]></content:encoded>
			<wfw:commentRss>http://nealenssle.com/blog/2011/02/28/how-to-pick-a-random-element-from-an-array/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to detect if a Rake task is being run with --trace</title>
		<link>http://nealenssle.com/blog/2010/11/12/how-to-detect-if-a-rake-task-is-being-run-with-trace/</link>
		<comments>http://nealenssle.com/blog/2010/11/12/how-to-detect-if-a-rake-task-is-being-run-with-trace/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 22:16:07 +0000</pubDate>
		<dc:creator>Neal Enssle</dc:creator>
				<category><![CDATA[untagged]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://nealenssle.com/blog/?p=360</guid>
		<description><![CDATA[So occasionally I want to output a debugging message for a Rake task. That&#8217;s easy enough. But what if I only want to output that message if the Rake task is being run with the --trace option? It turns out the answer is to check the Rake.application.options.trace flag in your task to determine if the [...]]]></description>
			<content:encoded><![CDATA[<p>So occasionally I want to output a debugging message for a Rake task. That&#8217;s easy enough. But what if I <strong>only</strong> want to output that message if the Rake task is being run with the <code>--trace</code> option? It turns out the answer is to check the <strong>Rake.application.options.trace</strong> flag in your task to determine if the <code>--trace</code> argument has been passed in, like so:</p>
<pre>
desc "The answer to life, the universe, and everything"
task :answer do |t|
  puts "42"
  if Rake.application.options.trace
    puts "Task '#{t.name}' is in --trace mode"
  end
end
</pre>
<p>Note that you can also set <strong>Rake.application.options.trace = true</strong> in your Rake task if you always want to see the stack trace information.</p>
]]></content:encoded>
			<wfw:commentRss>http://nealenssle.com/blog/2010/11/12/how-to-detect-if-a-rake-task-is-being-run-with-trace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to become a better programmer in 90 days</title>
		<link>http://nealenssle.com/blog/2010/10/13/how-to-become-a-better-programmer-in-90-days/</link>
		<comments>http://nealenssle.com/blog/2010/10/13/how-to-become-a-better-programmer-in-90-days/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 10:41:07 +0000</pubDate>
		<dc:creator>Neal Enssle</dc:creator>
				<category><![CDATA[untagged]]></category>
		<category><![CDATA[better]]></category>
		<category><![CDATA[boulder]]></category>
		<category><![CDATA[conferences]]></category>
		<category><![CDATA[foraker]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[reading]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://nealenssle.com/blog/?p=350</guid>
		<description><![CDATA[Foraker Labs just posted this (unofficial) YouTube video of the lightning talk I had a chance to give at the Mountain.rb Ruby conference last week in downtown Boulder, Colorado:
How to Become a Better Programmer in 90 Days
In this brief talk I present highlights from three books on my required reading list that (I believe) will [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.foraker.com">Foraker Labs</a> just posted this (unofficial) YouTube video of the lightning talk I had a chance to give at the <a href="http://mountainrb.com">Mountain.rb</a> Ruby conference last week in downtown Boulder, Colorado:</p>
<p><a href="http://www.youtube.com/watch?v=Wzk4rJCvICc">How to Become a Better Programmer in 90 Days</a></p>
<p>In this brief talk I present highlights from three books on my required reading list that (I believe) will help make you a better programmer:</p>
<ul>
<li style="margin-bottom: 5px;"><em><a href="http://www.amazon.com/dp/1934356344?tag=neaens-20&amp;camp=14573&amp;creative=327641&amp;linkCode=as1&amp;creativeASIN=1934356344&amp;adid=0P6TDEJ0NMPM5XR0T8M9&amp;">The Passionate Programmer</a> </em>by Chad Fowler</li>
<li style="margin-bottom: 5px;"><a href="http://www.amazon.com/dp/0132350882?tag=neaens-20&amp;camp=14573&amp;creative=327641&amp;linkCode=as1&amp;creativeASIN=0132350882&amp;adid=1MJG11X0VN3DHBF9M1MB&amp;"><em>Clean Code</em></a> by Robert C. Martin</li>
<li><em><a href="http://www.amazon.com/dp/0201485672?tag=neaens-20&amp;camp=14573&amp;creative=327641&amp;linkCode=as1&amp;creativeASIN=0201485672&amp;adid=1GJ08XSF6ETN06SZ737P&amp;">Refactoring</a></em> by Martin Fowler</li>
</ul>
<p>Thanks to <a href="http://twitter.com/#!/derekoncastiron">Derek Olson</a> for taping and editing, and thanks again to <a href="http://twitter.com/#!/mghaught">Marty Haught</a> for organizing the conference!</p>
]]></content:encoded>
			<wfw:commentRss>http://nealenssle.com/blog/2010/10/13/how-to-become-a-better-programmer-in-90-days/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mountain.rb 2010 recap</title>
		<link>http://nealenssle.com/blog/2010/10/11/mountain-rb-2010-recap/</link>
		<comments>http://nealenssle.com/blog/2010/10/11/mountain-rb-2010-recap/#comments</comments>
		<pubDate>Mon, 11 Oct 2010 17:17:02 +0000</pubDate>
		<dc:creator>Neal Enssle</dc:creator>
				<category><![CDATA[untagged]]></category>
		<category><![CDATA[boulder]]></category>
		<category><![CDATA[conferences]]></category>
		<category><![CDATA[foraker]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://nealenssle.com/blog/?p=348</guid>
		<description><![CDATA[I had a great time along with some of the rest of the Foraker crew at Mountain.rb, Boulder&#8217;s own Ruby conference.
Check out my recap of Mountain.rb, posted in two parts on the Foraker blog.
]]></description>
			<content:encoded><![CDATA[<p>I had a great time along with some of the rest of the Foraker crew at Mountain.rb, Boulder&#8217;s own Ruby conference.</p>
<p>Check out my <a href="http://blog.foraker.com/2010/10/updates-from-mountain-rb-conference-day/">recap of Mountain.rb</a>, posted in two parts on the Foraker blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://nealenssle.com/blog/2010/10/11/mountain-rb-2010-recap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to find your Ruby gem installation path</title>
		<link>http://nealenssle.com/blog/2010/03/30/ruby-gem-installation-pat/</link>
		<comments>http://nealenssle.com/blog/2010/03/30/ruby-gem-installation-pat/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 11:24:00 +0000</pubDate>
		<dc:creator>Neal Enssle</dc:creator>
				<category><![CDATA[untagged]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rubygems]]></category>

		<guid isPermaLink="false">http://nealenssle.com/blog/?p=339</guid>
		<description><![CDATA[It took me a bit too long to Google this, so I thought it was worth a note: You can find the location or path to where your Ruby gems are installed at with this command:

gem environment gemdir

Hope it&#8217;s useful!
]]></description>
			<content:encoded><![CDATA[<p>It took me a bit too long to Google this, so I thought it was worth a note: You can find the location or path to where your Ruby gems are installed at with this command:</p>
<pre language="Ruby">
gem environment gemdir
</pre>
<p>Hope it&#8217;s useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://nealenssle.com/blog/2010/03/30/ruby-gem-installation-pat/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to find the name of the current Rake task</title>
		<link>http://nealenssle.com/blog/2009/11/14/how-to-find-the-name-of-the-current-rake-task/</link>
		<comments>http://nealenssle.com/blog/2009/11/14/how-to-find-the-name-of-the-current-rake-task/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 03:15:59 +0000</pubDate>
		<dc:creator>Neal Enssle</dc:creator>
				<category><![CDATA[untagged]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://nealenssle.com/blog/?p=161</guid>
		<description><![CDATA[A few weeks ago I needed a Rake task to answer a simple question for me:
&#8220;What&#8217;s my name?&#8221;
I honestly can&#8217;t quite remember why exactly the task needed to know it&#8217;s own name, but at the time it seemed important and I spent a couple hours digging about before I found out that Rake tasks are [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I needed a Rake task to answer a simple question for me:</p>
<p>&#8220;What&#8217;s my name?&#8221;</p>
<p>I honestly can&#8217;t quite remember <em>why exactly</em> the task needed to know it&#8217;s own name, but at the time it seemed important and I spent a couple hours digging about before I found out that Rake tasks are shy by nature. Or at least when implemented the way almost every tutorial tells you to implement them:</p>
<pre>
namespace :life do

  desc "The answer to life, the universe, and everything"
  task :answer do
    puts "The answer to life, the universe, and everything is 42."
  end

end
</pre>
<p>But how do I know what the name of the current task is?  Well, after making a couple of random attempts (like &#8220;puts task.name&#8221;) and digging around in the <em>very sparse</em> documentation on the <a href="http://rake.rubyforge.org/">Rake homepage</a>, I stumbled  across a bit of documentation that talked about &#8220;Tasks with Actions&#8221;:</p>
<blockquote><p>
Actions are defined by passing a block to the task method. Any Ruby code can be placed in the block. The block may reference the task object via the block parameter.</p>
<pre>
task :name => [:prereq1, :prereq2] do |t|
  # actions (may reference t)
end
</pre>
</blockquote>
<p>Ah ha! &#8220;The block may reference the task object via the block parameter.&#8221;  That&#8217;s exactly what I was looking for.  Adding the block parameter allows us to reference the task object itself. And the task object itself has a good bit of useful meta information:</p>
<pre>
namespace :life do

  desc "The answer to life, the universe, and everything"
  task :answer do |t|
    puts t.name
    puts t.comment
    puts t.scope
  end

end
</pre>
<p>The task now returns the following:</p>
<pre>
life:answer
The answer to life, the universe, and everything
life
</pre>
<p>The first line of output is nifty, and answers the &#8220;What&#8217;s my name?&#8221; question with the fully scoped name of the task. Given that much it&#8217;s probably not hard to return the task name in even the most deeply namespaced Rakefile. The second line is the &#8220;comment&#8221; &#8212; actually the description of the task.  And the third line gets us the scope (namespaces). There are more methods available, but check teh googles for &#8220;Rake::Task api&#8221;.</p>
<p>So with this meta information we can do something useful like:</p>
<pre>
namespace :life do

  desc "The answer to life, the universe, and everything"
  task :answer do |t|
    puts "#{t.comment} is 42."
  end

end
</pre>
<p>Voila. And that&#8217;s probably enough meta for one day.</p>
]]></content:encoded>
			<wfw:commentRss>http://nealenssle.com/blog/2009/11/14/how-to-find-the-name-of-the-current-rake-task/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

