<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Ruby Fleebie</title>
	
	<link>http://www.rubyfleebie.com</link>
	<description>Rediscovering the joy of programming</description>
	<lastBuildDate>Fri, 11 Jan 2013 16:28:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/rubyfleebie" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="rubyfleebie" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><image><link>http://www.rubyfleebie.com</link><url>http://feeds.feedburner.com/~fc/rubyfleebie?bg=C42413&amp;fg=ffffff&amp;anim=0</url><title>Join us on RF</title></image><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">rubyfleebie</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Run bundle install with the –binstubs option</title>
		<link>http://www.rubyfleebie.com/run-bundle-install-with-the-binstubs-option/</link>
		<comments>http://www.rubyfleebie.com/run-bundle-install-with-the-binstubs-option/#comments</comments>
		<pubDate>Tue, 04 Dec 2012 21:47:23 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[short & sweet]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/?p=465</guid>
		<description><![CDATA[It&#8217;s been a little while that I have decided to always extract my gem binaries into my rails application &#8220;bin&#8221; path. That way, I always execute binaries by specifying the relative path. For example &#8220;./bin/rails g model User&#8221;. At first I wasn&#8217;t sure about the idea. I was like: &#8220;Wait a minute! I will have [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a little while that I have decided to always extract my gem binaries into my rails application &#8220;bin&#8221; path. That way, I always execute binaries by specifying the relative path. For example &#8220;./bin/rails g model User&#8221;. At first I wasn&#8217;t sure about the idea. I was like: &#8220;Wait a minute! I will have to type &#8220;./bin/&#8221; all the time?! It will get annoying really fast!&#8221;. This turned to be an unfounded fear. Having to type &#8220;./bin/rails&#8221; or &#8220;./bin/rake&#8221; is a good thing and it feels really natural. When you do this, there is no magic involved: you know exactly WHICH binary is going to be executed. </p>
<h3>Isn&#8217;t it exactly like typing &#8220;bundle exec&#8221; ?</h3>
<p>Yes, you&#8217;re right&#8230; it&#8217;s more or less the same thing. But I find that having to type &#8220;./bin/&#8221; is even more obvious. Believe me, you will get the hang of it quickly. Anyway, with TAB completion, it&#8217;s not like you have to type &#8220;./bin&#8221; really. It will look more like &#8220;./b&#8221; then TAB. It becomes second nature really fast.</p>
<h3>Wow! This is the discovery of the century! I&#8217;m sold, how can I do this ? (end sarcasm)</h3>
<p>Whenever you update your Gemfile, you do</p>
<p><strong>bundle &#8211;binstubs</strong></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Bucb5d6A29Y:WM424L_PVNU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Bucb5d6A29Y:WM424L_PVNU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=Bucb5d6A29Y:WM424L_PVNU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Bucb5d6A29Y:WM424L_PVNU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=Bucb5d6A29Y:WM424L_PVNU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Bucb5d6A29Y:WM424L_PVNU:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=Bucb5d6A29Y:WM424L_PVNU:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Bucb5d6A29Y:WM424L_PVNU:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Bucb5d6A29Y:WM424L_PVNU:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Bucb5d6A29Y:WM424L_PVNU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/run-bundle-install-with-the-binstubs-option/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Nested has_many :through</title>
		<link>http://www.rubyfleebie.com/nested-has_many-through/</link>
		<comments>http://www.rubyfleebie.com/nested-has_many-through/#comments</comments>
		<pubDate>Fri, 27 Apr 2012 19:12:52 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[short & sweet]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/?p=452</guid>
		<description><![CDATA[Hi (Oh my God&#8230; he just started his blog post with &#8216;Hi&#8217;), Did you know that as of Rails 3.1, you can have nested has_many :through clauses in your models? Here is a concrete example to understand what I mean:]]></description>
			<content:encoded><![CDATA[<p>Hi (Oh my God&#8230; he just started his blog post with &#8216;Hi&#8217;),</p>
<p>Did you know that as of Rails 3.1, you can have <a href="https://rails.lighthouseapp.com/projects/8994/tickets/1152-support-for-nested-has_many-through-associations">nested has_many :through clauses</a> in your models? Here is a concrete example to understand what I mean:</p>
<pre class="brush: ruby; title: ; notranslate">
  class SportSchedule &lt; ActiveRecord::Base
    has_many :gamedays
    has_many :games, :through =&gt; :gamedays
    has_many :results, :through =&gt; :games # &lt;= You could not do this before Rails 3.1

   ...
   def has_results?
     !self.results.empty?
   end
  end
</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=7MvIXA3nOMo:WUQ3vW9MSaQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=7MvIXA3nOMo:WUQ3vW9MSaQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=7MvIXA3nOMo:WUQ3vW9MSaQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=7MvIXA3nOMo:WUQ3vW9MSaQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=7MvIXA3nOMo:WUQ3vW9MSaQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=7MvIXA3nOMo:WUQ3vW9MSaQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=7MvIXA3nOMo:WUQ3vW9MSaQ:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=7MvIXA3nOMo:WUQ3vW9MSaQ:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=7MvIXA3nOMo:WUQ3vW9MSaQ:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=7MvIXA3nOMo:WUQ3vW9MSaQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/nested-has_many-through/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How To Strip Insignificant Zeros From a Float In Rails</title>
		<link>http://www.rubyfleebie.com/strip-insignificant-zeros-from-a-float-in-rails/</link>
		<comments>http://www.rubyfleebie.com/strip-insignificant-zeros-from-a-float-in-rails/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 14:47:00 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[short & sweet]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[helpers]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/?p=428</guid>
		<description><![CDATA[I had a float attribute in a Rails application and wanted to strip non-significant zeros when displaying it on a page. With the number_with_precision helper from ActionView, that&#8217;s a trivial thing:]]></description>
			<content:encoded><![CDATA[<p>I had a float attribute in a Rails application and wanted to strip non-significant zeros when displaying it on a page. With the <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_with_precision">number_with_precision</a> helper from ActionView, that&#8217;s a trivial thing:</p>
<pre class="brush: ruby; light: true; title: ; notranslate">
number_with_precision(
  3.50,
  strip_insignificant_zeros: true,
  precision: 2
)
# =&gt; &quot;3.5&quot;
</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=QHXWxFJCLJE:7pc6fpKodyw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=QHXWxFJCLJE:7pc6fpKodyw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=QHXWxFJCLJE:7pc6fpKodyw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=QHXWxFJCLJE:7pc6fpKodyw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=QHXWxFJCLJE:7pc6fpKodyw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=QHXWxFJCLJE:7pc6fpKodyw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=QHXWxFJCLJE:7pc6fpKodyw:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=QHXWxFJCLJE:7pc6fpKodyw:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=QHXWxFJCLJE:7pc6fpKodyw:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=QHXWxFJCLJE:7pc6fpKodyw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/strip-insignificant-zeros-from-a-float-in-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to hook to an Array instance in a Ruby module</title>
		<link>http://www.rubyfleebie.com/how-to-hook-to-an-array-instance-in-a-ruby-module/</link>
		<comments>http://www.rubyfleebie.com/how-to-hook-to-an-array-instance-in-a-ruby-module/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 15:49:46 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[short & sweet]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/?p=432</guid>
		<description><![CDATA[On some project we needed to create a module containing an Array attribute. We wanted to hook onto some of the methods of this particular Array instance to call our own code. Here is how we did it: And now the output:]]></description>
			<content:encoded><![CDATA[<p>On some project we needed to create a module containing an Array attribute. We wanted to hook onto some of the methods of this particular Array instance to call our own code. Here is how we did it:</p>
<pre class="brush: ruby; title: ; notranslate">
module TheModule
  attr_reader :items
  def initialize(*args)
    @items = []

    def @items.&lt;&lt;(item)
      super
      &quot;You added the item #{item} with &lt;&lt;!&quot;
    end

    def @items.push(item)
      super
      &quot;You added the item #{item} with push!&quot;
    end
    super
  end
end

class TheClass
  include TheModule
end
</pre>
<p>And now the output:</p>
<pre class="brush: ruby; title: ; notranslate">
x = TheClass.new
x.items   # =&gt; []
x.items &lt;&lt; 'blue' # =&gt; You added the item 'blue' with &lt;&lt;!
x.items.push 'orange' # =&gt; You added the item 'orange' with push!
x.items # =&gt; [&quot;blue&quot;, &quot;orange&quot;]
</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=w1q_MXJaJMg:W1e_UGndAZQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=w1q_MXJaJMg:W1e_UGndAZQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=w1q_MXJaJMg:W1e_UGndAZQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=w1q_MXJaJMg:W1e_UGndAZQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=w1q_MXJaJMg:W1e_UGndAZQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=w1q_MXJaJMg:W1e_UGndAZQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=w1q_MXJaJMg:W1e_UGndAZQ:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=w1q_MXJaJMg:W1e_UGndAZQ:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=w1q_MXJaJMg:W1e_UGndAZQ:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=w1q_MXJaJMg:W1e_UGndAZQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/how-to-hook-to-an-array-instance-in-a-ruby-module/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Every Little Things Capistrano Does Is Magic</title>
		<link>http://www.rubyfleebie.com/every-little-things-capistrano-does-is-magic/</link>
		<comments>http://www.rubyfleebie.com/every-little-things-capistrano-does-is-magic/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 19:26:13 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Easy reading]]></category>
		<category><![CDATA[bundler]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rvm]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/?p=378</guid>
		<description><![CDATA[During all these years, Capistrano has been for me a magical gnome that I invoke by saying &#8220;cap deploy, my magical friend!&#8221; and then I close my eyes, sing a happy song in my head and when the gnome has finished his magic, I hit F5 to see if all went well. And of course, [...]]]></description>
			<content:encoded><![CDATA[<p>During all these years, <a href="https://github.com/capistrano/capistrano/wiki/2.x-Getting-Started">Capistrano</a> has been for me a magical gnome that I invoke by saying &#8220;cap deploy, my magical friend!&#8221; and then I close my eyes, sing a happy song in my head and when the gnome has finished his magic, I hit F5 to see if all went well. And of course, if it didn&#8217;t, I blame the damn elf.</p>
<p>I am proud of this introduction. I will take a sip of coffee and read it again, hold on. Yes this intro was good, I think I should write about magical little beings more often.</p>
<p>If you are like me, you never paid much attention to capistrano and the way it works. At the exception of the famous &#8220;cap deploy&#8221; command, you never really <em>wanted</em> to get involved in the process. For this reason you have copied and pasted the same old deployment recipe in all of your projects over the years, only changing some parameters like the application name and the emplacement of the git repository.</p>
<p>The fact that capistrano is doing magical things doesn&#8217;t really help in this regard. My goal in this post is to explain some of the not so obvious parts of capistrano. With minimal efforts we can have a better idea of what capistrano does and feel more in control when deploying an application.</p>
<p><strong>Capistrano is magic</strong></p>
<p>Like many things in the ruby world, there is a fair bit of magic involved in capistrano. For example, when you type &#8220;cap deploy&#8221;, there is a bunch of things that happen, but what things exactly? What tasks are being called? This is not obvious. First of all, &#8220;deploy&#8221; is not a task written in your own recipe file, it is a namespace located in the capistrano gem. Take a look:</p>
<pre class="brush: ruby; title: ; notranslate">
namespace :deploy do
  desc &lt;&lt;-DESC
    Deploys your project. This calls both `update' and `restart'. Note that \
    this will generally only work for applications that have already been deployed \
    once. For a &quot;cold&quot; deploy, you'll want to take a look at the `deploy:cold' \
    task, which handles the cold start specifically.
  DESC
  task :default do
    update
    restart
  end
#...
</pre>
<p>As you can see, the :default task is invoked when you type &#8220;cap deploy&#8221;, which in turns will call &#8220;update&#8221; and &#8220;restart&#8221;. </p>
<p>This is why you never got to see a call to the :restart task in your own recipe file. I know that during all these years there was a secret part of your brain that was¸wondering about this stuff, while the not-so-secret part really didn&#8217;t care. </p>
<p><strong>Capistrano and Bundler</strong></p>
<pre class="brush: ruby; title: ; notranslate">
  require 'bundler/capistrano'
</pre>
<p>This line adds some <a href="http://gembundler.com/">bundler</a> magical stuff to your recipe. It will install your bundle (with the &#8211;deployment flag) when deploying, meaning that all your gems will be vendored to <em>yourapp/shared/bundle</em>.</p>
<p><strong>Capistrano and the Asset Pipeline</strong></p>
<pre class="brush: ruby; title: ; notranslate">
load &quot;deploy/assets&quot;
</pre>
<p>This line adds some magical stuff for compatibility with the Rails 3.1+ <a href="http://guides.rubyonrails.org/asset_pipeline.html">asset pipeline</a>. More precisely, it will precompile your assets. This is an almost essential part when you use the asset pipeline in production. The other solution is to precompile locally and push the assets to your repository, not a good idea in my opinion. The sad part is that precompiling assets can slow down your deployment quite severly. If you use GIT, you might like this <a href="http://www.bencurtis.com/2011/12/skipping-asset-compilation-with-capistrano/">smart solution</a> from Ben Curtis to skip assets precompilation.</p>
<p><strong>Capistrano and RVM</strong></p>
<pre class="brush: ruby; title: ; notranslate">
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require &quot;rvm/capistrano&quot;
set :rvm_ruby_string, 'ruby-1.9.2-head@rails3.2'
set :rvm_type, :user
</pre>
<p>This tells capistrano to switch to a specific ruby version + gemset when connected to the server. The gemset (i.e. @rails3.2) is the tricky part because it makes you think that, when capistrano will invoke <em>bundle install</em>, your gems will be installed in <em>.rvm/gems/ruby-1.9.2-head@rails3.2/gems</em>. This is not the case. Remember that we have just told bundler to install the gems in <em>yourapp/shared/bundle/</em>. </p>
<p><strong>So why do we bother with the gemset anyway?</strong></p>
<p>One reason is that the <strong>bundler gem itself</strong> will be invoked by capistrano on your server in the gemset specified in the <em>rvm_ruby_string</em> variable. It can be useful to specify a gemset if you want to use a specific version of bundler.</p>
<p><img src="http://www.rubyfleebie.com/wp-content/uploads/theend031_0.jpg" alt="That's all folks!" /></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Q4IJHWYSpas:ERaF5kenvFY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Q4IJHWYSpas:ERaF5kenvFY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=Q4IJHWYSpas:ERaF5kenvFY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Q4IJHWYSpas:ERaF5kenvFY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=Q4IJHWYSpas:ERaF5kenvFY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Q4IJHWYSpas:ERaF5kenvFY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=Q4IJHWYSpas:ERaF5kenvFY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Q4IJHWYSpas:ERaF5kenvFY:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Q4IJHWYSpas:ERaF5kenvFY:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=Q4IJHWYSpas:ERaF5kenvFY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/every-little-things-capistrano-does-is-magic/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Should ruby go the haml route and uses significant whitespaces?</title>
		<link>http://www.rubyfleebie.com/should-ruby-go-the-haml-route-and-uses-significant-whitespaces/</link>
		<comments>http://www.rubyfleebie.com/should-ruby-go-the-haml-route-and-uses-significant-whitespaces/#comments</comments>
		<pubDate>Mon, 30 May 2011 12:00:30 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Easy reading]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/?p=344</guid>
		<description><![CDATA[Before I start, let me get something straight: I&#8217;m not saying it would be a good or bad idea&#8230; I&#8217;m just asking the question. I must say that my first experience with a significant whitespace language was a disaster. The first time I had to use Python was on a server via ssh. I was [...]]]></description>
			<content:encoded><![CDATA[<p>Before I start, let me get something straight: I&#8217;m not saying it would be a good or bad idea&#8230; I&#8217;m just asking the question.</p>
<p>I must say that my first experience with a significant whitespace language was a disaster. The first time I had to use Python was on a server via ssh. I was in a hurry and wanted to monkey patch some buggy script I had installed. So without thinking too much I opened the script with a text editor called <a href="http://www.nano-editor.org/">nano</a>. The problem is that a TAB in nano produces between 173 and 177 white spaces. Realizing this I decided to refrain from indenting one line or two because it was too ugly and unreadable. Then python told me that I could not do this&#8230; and at the time I remember thinking it was unacceptable that a script start to malfunction just because of a few missing whitespaces. Anyway, I spent some long minutes trying to fix a few indentation issues (in nano! I still didn&#8217;t realize it was the source of the problem) and it was very tedious.  Had I try debugging the python script on my local computer with gedit for example, things would surely have turned out differently.</p>
<p><strong>Then Haml came&#8230; and I stayed away</strong></p>
<p>This unpleasant experience I had with Python had a rather negative side effect: It made me completely ignore <a href="http://haml-lang.com/">Haml</a> for a long time, which is sad because it is such a great alternative to erb. </p>
<p>But now I use Haml, and I really like it. Not having to &#8220;close my tags&#8221; is more satisfying than I thought it would be. I always delight when I realize I was about to write a &#8220;- end&#8221; tag to close a &#8220;- @items.each&#8221; loop or something like that. I don&#8217;t have to! Less typing, less noise, cleaner, prettier, I love this! Wouldn&#8217;t be nice if we could do away with the &#8220;end&#8221; keyword in ruby as well?</p>
<p>Just to give us an idea, here is how an actual class from the Haml gem would look like if it was written in Significant Whitespace ruby:</p>
<pre class="brush: ruby; title: ; notranslate">
    class ParseNode &lt; Struct.new(:type, :line, :value, :parent, :children)
      def initialize(*args)
        super
        self.children ||= []

      def inspect
        text = &quot;(#{type} #{value.inspect}&quot;
        children.each {|c| text &lt;&lt; &quot;\n&quot; &lt;&lt; c.inspect.gsub(/^/, &quot;  &quot;)}
        text + &quot;)&quot;
</pre>
<p>Great, it sill looks like ruby. We just removed some noise to make it even more readable.</p>
<p>Let&#8217;s convert a longer method, still from the Haml gem, to see how it would look like:</p>
<pre class="brush: ruby; title: ; notranslate">
    def parse_new_attributes(line)
      line = line.dup
      scanner = StringScanner.new(line)
      last_line = @index
      attributes = {}

      scanner.scan(/\(\s*/)
      loop do
        name, value = parse_new_attribute(scanner)
        break if name.nil?

        if name == false
          text = (Haml::Shared.balance(line, ?(, ?)) || [line]).first
          raise Haml::SyntaxError.new(&quot;Invalid attribute list: #{text.inspect}.&quot;, last_line - 1)

        attributes[name] = value
        scanner.scan(/\s*/)

        if scanner.eos?
          line &lt;&lt; &quot; &quot; &lt;&lt; @next_line.text
          last_line += 1
          next_line
          scanner.scan(/\s*/)

      static_attributes = {}
      dynamic_attributes = &quot;{&quot;
      attributes.each do |name, (type, val)|
        if type == :static
          static_attributes[name] = val
        else
          dynamic_attributes &lt;&lt; inspect_obj(name) &lt;&lt; &quot; =&gt; &quot; &lt;&lt; val &lt;&lt; &quot;,&quot;

      dynamic_attributes &lt;&lt; &quot;}&quot;
      dynamic_attributes = nil if dynamic_attributes == &quot;{}&quot;

      return [static_attributes, dynamic_attributes], scanner.rest, last_line
</pre>
<p>Well, not bad at all&#8230; the only problem is that the loop is quite long and I had to double-check to know if the &#8220;static_attributes&#8221; statement was part of the loop or right after. This kind of double checking could get on my nerves fast. </p>
<p>I&#8217;m still undecided. I dislike end tags but they can clear things up sometimes. Anyway, I guess we probably never see this implemented in ruby. What&#8217;s your thoughts on significant whitespace languages?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=oHz4IFYg3Xo:-EUnrkt8hmA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=oHz4IFYg3Xo:-EUnrkt8hmA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=oHz4IFYg3Xo:-EUnrkt8hmA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=oHz4IFYg3Xo:-EUnrkt8hmA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=oHz4IFYg3Xo:-EUnrkt8hmA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=oHz4IFYg3Xo:-EUnrkt8hmA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=oHz4IFYg3Xo:-EUnrkt8hmA:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=oHz4IFYg3Xo:-EUnrkt8hmA:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=oHz4IFYg3Xo:-EUnrkt8hmA:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=oHz4IFYg3Xo:-EUnrkt8hmA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/should-ruby-go-the-haml-route-and-uses-significant-whitespaces/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>Review of some testing tools for ruby</title>
		<link>http://www.rubyfleebie.com/testing-tools-i-use/</link>
		<comments>http://www.rubyfleebie.com/testing-tools-i-use/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 13:24:44 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[In depth]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/?p=256</guid>
		<description><![CDATA[I never wrote anything about tests on this blog and the reason is simple: I never considered testing to be something fun. The little slogan you see at the top left (a bit cheesy I admit) is the reason why I started Ruby Fleebie back in 2007. I was amazed by the possibilities of the [...]]]></description>
			<content:encoded><![CDATA[<p>I never wrote anything about tests on this blog and the reason is simple: I never considered testing to be something fun. The little slogan you see at the top left (a bit cheesy I admit) is the reason why I started Ruby Fleebie back in 2007. I was amazed by the possibilities of the ruby language and the way you could express complex stuff in a very concise an elegant manner.</p>
<p>Now does this mean I don&#8217;t write tests just because I think they aren&#8217;t fun? Of course not. I do write tests&#8230; I just don&#8217;t blog about them because they don&#8217;t excite me very much. I&#8217;m currently on a quest to find a way to enjoy testing more. This is a work in progress for me and so far I have managed to draw at least this conclusion: To enjoy testing a bit more, one need a killer setup and great testing tools to work with.</p>
<h2>Continuous testing</h2>
<p>Running &#8220;rake test&#8221; once in a while is a very simple setup. The biggest problem with this approach is that it disconnect you from your &#8220;flow&#8221;. You have to remember about running this command and if you forget (I know I do) no one will know about it.</p>
<p>So a part of the solution to improve my testing setup was to have my tests run continuously. The most popular library that help with this is probably <a href="http://www.zenspider.com/ZSS/Products/ZenTest/">autotest</a>. It fixes once and for all the problem of forgetting to run my tests.</p>
<p>So we have autotest running our tests in the background. That&#8217;s great&#8230; but it could be better. the output that Test:Unit or RSpec spits is verbose, hard to read and hidden somewhere on a terminal window. I wanted the testing phase to be integrated as much as possible into my other programming tasks, so I decided to install <a href="https://github.com/carlosbrando/autotest-notification#readme">autotest-notifications</a>,  a nice autotest plugin that knows how to talk to libnotify (linux), growl (mac) or snarl (windows) and it tells you if you have failing tests. This is the kind of OS integration I like! I am a Linux guy so I had to install libnotify-bin in my ubuntu box before I could use the plugin. Mac users will have to make sure growl and growlnotify is installed on their machines. As for windows users, they will have to install snarl. Here is a screenshot showing how it looks in Linux :</p>
<p><img src="http://www.ctets.org/images/at_notify.png" alt="" /></p>
<p>To start autotest-notifications, type an-install. To stop, type an-uninstall.</p>
<h2>Other testing tools</h2>
<p>Now that my tests run continously, I can concentrate on finding other testing tools that will help me write tests more easily and more rapidly.</p>
<p><strong>Test::Unit / RSpec</strong></p>
<p>I always used <a href="http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html">Test::Unit</a>. I tried <a href="https://github.com/dchelimsky/rspec">RSpec</a> for the first time very recently and was quite pleased with it. I don&#8217;t see that much difference between the two except in the syntax. The only thing I can say is that when I use Test::Unit, I absolutely want to use Shoulda as well. When I use RSpec, shoulda is less essential but I still use it.</p>
<p><strong>Shoulda</strong></p>
<p>I&#8217;d say that <a href="https://github.com/thoughtbot/shoulda">shoulda</a> is Test::Unit best friend. It gives you a nice set of useful test macros and some great semantic constructs that will improve the readability of your tests.</p>
<p><strong>Capybara (I give to this one the gold medal)</strong></p>
<p>Question: What&#8217;s missing if I only use Test::Unit or RSpec ?<br />
Answer: A good integration testing framework</p>
<p><a href="https://github.com/jnicklas/capybara">Capybara</a> is a great tool for higher level testing. It&#8217;s the kind of testing a non-programmer can understand: <em>when I click this link then I should see this and when I fill this form then it should take me there and so on</em>.</p>
<p>Capybara is a magician that will actually click on your links, fill out your forms and even triggers your javascript. He&#8217;s like a end-user testing your app in a hidden browser. Seriously I think these tests are great to have and capybara does a wonderful job to help you write them.</p>
<p><strong>Cucumber</strong></p>
<p>To be frank, I find this one more difficult to love. If there&#8217;s one tool I plan to stop using in the near future, it&#8217;s probably <a href="http://cukes.info">cucumber</a>. But to each its own!</p>
<p>For those who don&#8217;t know, Cucumber is a DSL that encourages Behaviour Driven Development. It lets you describe features before you start implementing them. The &#8220;twist&#8221; is that you describe these features in plain english, or I should rather say, in plain <a href="https://github.com/aslakhellesoy/cucumber/wiki/gherkin">Gherkin</a>. You then take each &#8220;plain Gherkin&#8221; instruction and you translate them into ruby code in another file called a &#8220;steps definition file&#8221;. For example:</p>
<p>Gherkin:</p>
<pre class="brush: ruby; title: ; notranslate">
Given a user called Bob
When he stumbles and fall flat on his face
Then he should lose only 1 tooth
</pre>
<p>Step definition file:</p>
<pre class="brush: ruby; title: ; notranslate">
Given /^a user called (.*)$^ do |user_name|
  @user = User.create(:name =&gt; user_name)
end

When /^he stumbles and fall flat on his face$/ do
  @user.stumble_and_fall!
end

Then /^he should lose only (\d+) (tooth|teeth)$/ do |count|
  @user.teeth_lost.should == count
end
</pre>
<p><strong>My problem with Cucumber</strong></p>
<p>I am the co-founder of a startup composed of 2 developers. We obviously don&#8217;t need something like the business friendly Gherkin language. For us this language is harder to understand than ruby code can be. Of course, when it&#8217;s some dead easy stuff like the example above, it looks cool, but when you start adding fixtures/factories into the mix and that you have several words in the expression that will be replaced in a regex later, then you begin to write features filled with black magic and you won&#8217;t want to touch them ever again because you know that a single tiny change will break them. For each Gherkin line I&#8217;m writing, I can&#8217;t refrain myself from thinking about the step definition that I will have to create for it. <strong>That is the main problem I have with Cucumber</strong>. As a developer I cannot write Gherkin like it was only plain english. So I often write what we could call <em>technical gherkin easy to translate in a regex-friendly step definition</em>&#8230; and sometimes this kind of technical language is a lot harder to appreciate than ruby. Even worse, writing this kind of <em>developer-friendly</em> Gherkin destroys the purpose of this language.</p>
<p><strong>Factory Girl</strong></p>
<p>This one gem will save you a lot of time&#8230; once you know how to use it!</p>
<p>What is <a href="https://github.com/thoughtbot/factory_girl">Factory Girl</a>? It&#8217;s simply a way to replace the somewhat cumbersome fixtures in Rails. You can see it this way: Instead of having a bunch of &#8220;static&#8221; data that will be loaded in your database everytime, with FactoryGirl you build ActiveRecord objects on the fly depending on your testing needs. Basically, you have to define one factory per model. In each factory, you define default values for every attributes you want (generally those that cannot be nil). These values will always be used unless you specify something different in your tests.</p>
<pre class="brush: ruby; title: ; notranslate">
Factory.define(:league) do |l|
  l.name &quot;The happy league&quot;
end

Factory.define(:season) do |s|
  s.starts_on Date.parse(&quot;2010/11/30&quot;)
  s.ends_on Date.parse(&quot;2011/02/18&quot;)
  s.association :league
end

Factory.define(:gameday) do |gd|
  gd.season {Season.first || Factory(:season)}
end

Factory.define(:team) do |t|
  #sequences are a good way to generate unique values
  t.sequence(:name) do |n|
    &quot;The big fat tigers - #{n}&quot;
  end
  t.season {Season.first || Factory(:season)}
end

Factory.define(:game) do |g|
  g.game_time DateTime.parse(&quot;7:00 PM&quot;)
  g.association :gameday
  g.association :team_a, :factory =&gt; :team
  g.association :team_b, :factory =&gt; :team
end
</pre>
<p>If I want to test something with a Game instance and I don&#8217;t really care about the other associated models, then I can simply write <em>Factory(:game)</em> and FactoryGirl will take care of creating all the associations for me. I don&#8217;t have to create a gameday then associate it to my game&#8230; then create a season and associate it to my gameday&#8230; then create a league and associate it to my season.  I can just type Factory(:game) and I will have a perfectly valid Game instance with all its associations.</p>
<p>I want to bring your attention on line #12 and #20. The way I define my association for the season factory is different. There is probably a better way to do this but I didn&#8217;t find any. Basically, instead of going the traditional route and do this:</p>
<pre class="brush: ruby; title: ; notranslate">
gd.association :season
</pre>
<p>I use a block to specify a condition. I do this because of the Game factory defined at line #23. You can see that I have a relation to the Gameday factory and two relations to the Team factory. <strong>Both these factories are associated with the Season factory</strong>. If I had made a standard association call (i.e. gd.association :season and t.association :season), three different seasons would have been created at line #25, #26 and #27. This is not what I wanted&#8230; I wanted the <strong>same</strong> season to be used.</p>
<p>FactoryGirl is a great fixture replacement, but as you see it got its quirks and it&#8217;s not the easiest tool to use.</p>
<h2>Conclusion</h2>
<p>So, am I a happy tester now? not yet, I&#8217;m afraid&#8230; but I&#8217;m getting there I guess. Feel free to leave me a comment and tell me which tools you use and how you integrate testing in your programming routine.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=epYg6ssVZRo:iNfOccteZUU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=epYg6ssVZRo:iNfOccteZUU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=epYg6ssVZRo:iNfOccteZUU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=epYg6ssVZRo:iNfOccteZUU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=epYg6ssVZRo:iNfOccteZUU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=epYg6ssVZRo:iNfOccteZUU:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=epYg6ssVZRo:iNfOccteZUU:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=epYg6ssVZRo:iNfOccteZUU:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=epYg6ssVZRo:iNfOccteZUU:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=epYg6ssVZRo:iNfOccteZUU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/testing-tools-i-use/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Interacting with MongoDB using Rails 3 and MongoMapper</title>
		<link>http://www.rubyfleebie.com/interacting-with-mongodb-using-rails-3-and-mongomapper/</link>
		<comments>http://www.rubyfleebie.com/interacting-with-mongodb-using-rails-3-and-mongomapper/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 18:30:03 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[short & sweet]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/?p=247</guid>
		<description><![CDATA[MongoDB is an opensource document-oriented database in the vein of CouchDB. It’s been a while since I wanted to try this kind of database on a Rails project. After reading this nice tutorial today I decided to take some time to create a sample Rails 3 app and put it on github. I chose to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mongodb.org/">MongoDB</a> is an opensource document-oriented database in the vein of <a href="http://couchdb.apache.org/">CouchDB</a>. It’s been a while since I wanted to try this kind of database on a Rails project. After reading this nice <a href="http://www.mongodb.org/display/DOCS/Rails+3+-+Getting+Started">tutorial</a> today I decided to take some time to create a sample Rails 3 app and put it on <a href="https://github.com/flamontagne/mongomapper-rails3-sample">github</a>.</p>
<p>I chose to use <a href="https://github.com/jnunemaker/mongomapper">MongoMapper</a>, a ruby object mapper for Mongo. MongoMapper uses ActiveModel and let you interact with a MongoDB database in a very <em>ActiveRecord way</em>. </p>
<p>Hope this sample app will help you getting started with MongoDB!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=FK27ux7833Y:bBY3okwP-8A:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=FK27ux7833Y:bBY3okwP-8A:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=FK27ux7833Y:bBY3okwP-8A:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=FK27ux7833Y:bBY3okwP-8A:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=FK27ux7833Y:bBY3okwP-8A:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=FK27ux7833Y:bBY3okwP-8A:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=FK27ux7833Y:bBY3okwP-8A:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=FK27ux7833Y:bBY3okwP-8A:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=FK27ux7833Y:bBY3okwP-8A:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=FK27ux7833Y:bBY3okwP-8A:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/interacting-with-mongodb-using-rails-3-and-mongomapper/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Generate round-robin sport schedules with RRSchedule</title>
		<link>http://www.rubyfleebie.com/generate-round-robin-sport-schedules-with-rrschedule/</link>
		<comments>http://www.rubyfleebie.com/generate-round-robin-sport-schedules-with-rrschedule/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 15:03:31 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Easy reading]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/?p=234</guid>
		<description><![CDATA[One of our projects, called Mon Curling, is a web application that helps recreational curling leagues with their schedules, results and standings. One thing that the app was NOT doing was to generate the schedule automatically. Instead, the league manager had to generate his schedule beforehand and enter all the matches manually in our interface. [...]]]></description>
			<content:encoded><![CDATA[<p>One of our projects, called <a href="http://www.moncurling.com/en">Mon Curling</a>, is a web application that helps recreational curling leagues with their schedules, results and standings.  One thing that the app was NOT doing was to generate the schedule automatically. Instead, the league manager had to generate his schedule beforehand and enter all the matches manually in our interface. </p>
<p>This will now change with the new gem I am working on called <a href="http://flamontagne.github.com/rrschedule">RRSchedule</a> (code is also on <a href="http://github.com/flamontagne/rrschedule">github</a>). </p>
<p>I realized that most sport leagues were using a <a href="http://en.wikipedia.org/wiki/Round-robin_tournament">round-robin</a> format for their seasons and this is how I had the idea to make a gem out of it. </p>
<p>The gem takes into consideration the number of available &#8220;playing surfaces&#8221; and multiple game times. Say for example that you want to generate a round-robin schedule for your 19-teams volleyball league where games are played every wednesday. If there are 3 volleyball fields available and that games are played at 7:00 PM and 9:00 PM. This means that 6 games can be played every gameday (3 volleyball fields * 2 game times). </p>
<p>Example:<br />
Gameday #1<br />
========<br />
A vs B on Volleyball field &#8220;A&#8221; will play at 7:00 PM<br />
C vs D on Volleyball field &#8220;B&#8221; will play at 7:00 PM<br />
E vs F on Volleyball field &#8220;C&#8221; will play at 7:00 PM<br />
G vs H on Volleyball field &#8220;A&#8221; will play at 9:00 PM<br />
I vs J on Volleyball field &#8220;B&#8221; will play at 9:00 PM<br />
K vs L on Volleyball field &#8220;C&#8221; will play at 9:00 PM</p>
<p>Since the round-robin round can not be completed on a single day, the remaining games in the round will be put on the next gameday and a new round will start right after.</p>
<p>I hope this gem will be useful to some people!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=ls9QpST7zDo:NYoiXZj1lVU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=ls9QpST7zDo:NYoiXZj1lVU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=ls9QpST7zDo:NYoiXZj1lVU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=ls9QpST7zDo:NYoiXZj1lVU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=ls9QpST7zDo:NYoiXZj1lVU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=ls9QpST7zDo:NYoiXZj1lVU:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=ls9QpST7zDo:NYoiXZj1lVU:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=ls9QpST7zDo:NYoiXZj1lVU:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=ls9QpST7zDo:NYoiXZj1lVU:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=ls9QpST7zDo:NYoiXZj1lVU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/generate-round-robin-sport-schedules-with-rrschedule/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to add methods to existing classes</title>
		<link>http://www.rubyfleebie.com/how-to-add-methods-to-existing-classes/</link>
		<comments>http://www.rubyfleebie.com/how-to-add-methods-to-existing-classes/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 16:12:52 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[short & sweet]]></category>

		<guid isPermaLink="false">http://www.rubyfleebie.com/?p=76</guid>
		<description><![CDATA[A quick and easy tip today. It won&#8217;t impress the veteran ruby developer, but it will impress every ruby newcomers, guaranteed! Say I have a horse racing ruby application that allow people to know information about every competing horses. I have an input box that people can use to enter the name of a horse. [...]]]></description>
			<content:encoded><![CDATA[<p>A quick and easy tip today. It won&#8217;t impress the veteran ruby developer, but it will impress every ruby newcomers, guaranteed!</p>
<p>Say I have a horse racing ruby application that allow people to know information about every competing horses. I have an input box that people can use to enter the name of a horse. Once they click OK, information about the specified horse is displayed to the user.</p>
<p>Instead of going the traditonal route, how about adding a &#8220;horse&#8221; method to the String class? It could not be easier :</p>
<pre class="brush: ruby; title: ; notranslate">
HORSES = [
  {
    :name =&gt; &quot;Jolly Jumper&quot;,
    :also_known_as =&gt; [&quot;Smart Arse&quot;,&quot;Lucky Luke friend&quot;],
    :speed =&gt; 3, :intelligence =&gt; 30,
    :favorite_quote =&gt; &quot;I am a horse, I don't have quotes&quot;
  },

  {
    :name =&gt; &quot;Incredibly Bad&quot;,
    :also_known_as =&gt; [&quot;Shame&quot;,&quot;The Pathetic&quot;],
    :speed =&gt; 2, :intelligence =&gt; 4,
    :favorite_quote =&gt; &quot;If you still put your money on me, you only have yourself to blame&quot;
  },

  {
    :name =&gt; &quot;Fast And Furious&quot;,
    :also_known_as =&gt; [&quot;The Strong Rebel&quot;,&quot;The Furious One&quot;],
    :speed =&gt; 50, :intelligence =&gt; 15,
    :favorite_quote =&gt; &quot;I am fast&quot;
  },

 {
    :name =&gt; &quot;Slow and Jerky&quot;,
    :also_known_as =&gt; [&quot;Tender&quot;,&quot;Terrible Choice&quot;],
    :speed =&gt; 1, :intelligence =&gt; 10,
    :favorite_quote =&gt; &quot;Pick me once, regret it for a lifetime.&quot;
  }
]

class String
  def horse
    res = HORSES.select { |h| h[:name] == self || h[:also_known_as].include?(self)}
    res.first if res.length&gt;0
  end
end

#Then you can do stuff like this :
horse = &quot;Tender&quot;.horse
if horse
	puts &quot;#{horse[:name]}, also known as #{horse[:also_known_as].join(&quot;, &quot;)}, has a speed of #{horse[:speed]} and an intelligence of #{horse[:intelligence]}. In its free time, this horse like to become all philosophic, look at the sky and say : '#{horse[:favorite_quote]}'&quot;
else
	puts &quot;This horse doesn't exists in our records&quot;
end
</pre>
<p>Talk about some great syntactic ruby sugar!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=a5MqLRXlV2k:RXBvvubmfqE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=a5MqLRXlV2k:RXBvvubmfqE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=a5MqLRXlV2k:RXBvvubmfqE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=a5MqLRXlV2k:RXBvvubmfqE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=a5MqLRXlV2k:RXBvvubmfqE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=a5MqLRXlV2k:RXBvvubmfqE:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?i=a5MqLRXlV2k:RXBvvubmfqE:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=a5MqLRXlV2k:RXBvvubmfqE:Gu391qSwH_A"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=Gu391qSwH_A" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=a5MqLRXlV2k:RXBvvubmfqE:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rubyfleebie?a=a5MqLRXlV2k:RXBvvubmfqE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/rubyfleebie?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.rubyfleebie.com/how-to-add-methods-to-existing-classes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
