<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users1</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/1" rel="self"/>
  <title>macournoyer</title>
  <updated>Sun Oct 19 22:13:46 -0700 2008</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor55699</id>
    <published>2008-10-19T22:13:46-07:00</published>
    <title>[Ruby] On Morse Code Encoder/Decoder</title>
    <content type="html">&lt;p&gt;awesome Magnus!&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/513-morse-code-encoder-decoder/refactors/55699" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor33533</id>
    <published>2008-09-26T18:00:54-07:00</published>
    <title>[PHP] On Mortgage Calculator</title>
    <content type="html">&lt;p&gt;yo guys, what's up with all the hate?
&lt;br /&gt;You need sweat and tender loving.
&lt;br /&gt;xx&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/505-mortgage-calculator/refactors/33533" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code491</id>
    <published>2008-09-14T18:11:09-07:00</published>
    <updated>2008-09-14T18:48:08-07:00</updated>
    <title>[Ruby] Very Simple Rack framework</title>
    <content type="html">&lt;p&gt;I'll be presenting &lt;a href="http://rack.rubyforge.org" target="_blank"&gt;http://rack.rubyforge.org&lt;/a&gt; this Tuesday at the first Montreal Against Rails (&lt;a href="http://www.montrealonrails.com/2008/09/11/montreal_against_rails-tuesday" target="_blank"&gt;http://www.montrealonrails.com/2008/09/11/montreal_against_rails-tuesday&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;I'll show how to use Rack and then I'd like to try something new (and probably crazy-stupid). Building a web framework with Rack is so easy, I'll be doing pair programming with anyone from the audience to create our own custom framework live during the presentation (in 30 min). We'll start with the code posted here on RefactorMyCode as the application code, we'll implement the framework code during the presentation. So submit your ideas here before the event.&lt;/p&gt;

&lt;p&gt;And make sure to RSVP (&lt;a href="http://upcoming.yahoo.com/event/1093407" target="_blank"&gt;http://upcoming.yahoo.com/event/1093407&lt;/a&gt;) if your in Montreal next Tuesday!&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre&gt;# This is what an application build with our framework would look like.
# Run with:
#   rackup app.ru

app = App.new do
  
  get &amp;quot;&amp;quot; do
    render &amp;quot;hi&amp;quot; # Specifies the body of the response
  end
  
  get &amp;quot;echo/(.*)&amp;quot; do |text| # Regexp matches are passed as block args
    render text
  end
  
  get &amp;quot;session/set&amp;quot; do
    session[params.first.key] = params.first.value
  end
  get &amp;quot;session&amp;quot; do
    render session.inspect
  end
  
  get &amp;quot;form&amp;quot; do
    render erb(:form) # Can have helper methods to render erb and the like
  end
  
  post &amp;quot;form&amp;quot; do
    render params.inspect
  end
  
end

run app&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/491-very-simple-rack-framework" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor14478</id>
    <published>2008-08-04T14:38:32-07:00</published>
    <title>[Ruby] On Ruby Custom Sort</title>
    <content type="html">&lt;p&gt;You can edit your entry using the link on the top right.
&lt;br /&gt;Author of original code posting can delete your entry but not commenters, just like on blogs.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/418-ruby-custom-search/refactors/14478" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor13579</id>
    <published>2008-07-22T20:58:47-07:00</published>
    <title>[Ruby] On Assignment from array</title>
    <content type="html">

&lt;pre&gt;v = (a[:k][0] rescue nil) || 1&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/394-assignment-from-array/refactors/13579" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor12025</id>
    <published>2008-06-27T19:59:25-07:00</published>
    <title>[Bash] On kill nginx master proces</title>
    <content type="html">&lt;p&gt;Not sure it's a good idea, master process controls worker procesess, that could cause some worker to loose connections.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/338-kill-nginx-master-proces/refactors/12025" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor12013</id>
    <published>2008-06-27T17:13:24-07:00</published>
    <title>[Bash] On kill nginx master proces</title>
    <content type="html">&lt;p&gt;Replace /usr/local/nginx/ w/ the path to your Nginx installation&lt;/p&gt;

&lt;pre&gt;sudo kill -INT `cat /usr/local/nginx/logs/nginx.pid`&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/338-kill-nginx-master-proces/refactors/12013" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor9152</id>
    <published>2008-06-03T14:58:43-07:00</published>
    <title>[Ruby] On Refactor "class &lt;&lt; self" into module</title>
    <content type="html">&lt;p&gt;I think this makes the code easier to understand&lt;/p&gt;

&lt;pre&gt;module StringReader   
  def string_reader(*params)
    params.each do |param|
      class_eval &amp;lt;&amp;lt;-EOS
        def #{param}
          @#{param}.to_s
        end
      EOS
    end
  end
end

&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/311-refactor-class-self-into-module/refactors/9152" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor4574</id>
    <published>2008-03-31T11:25:06-07:00</published>
    <title>[C#] On Since I Cannot Message People...</title>
    <content type="html">&lt;p&gt;hey Rob, why not post some real code instead to check?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/270-since-i-cannot-message-people/refactors/4574" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor2282</id>
    <published>2008-02-13T02:05:15-08:00</published>
    <title>[Ruby] On Including modules degradably</title>
    <content type="html">&lt;p&gt;Seems like there was a caching issue preventing this submission from being shown on the front page. Sorry about that&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/230-including-modules-degradably/refactors/2282" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor1344</id>
    <published>2008-01-03T14:41:38-08:00</published>
    <title>[Ruby] On Rubyize this : 5th edition</title>
    <content type="html">&lt;p&gt;Sorry about the form not working Jason, should be fixed now&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/203-rubyize-this-5th-edition/refactors/1344" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor1339</id>
    <published>2008-01-03T14:26:58-08:00</published>
    <title>[Ruby] On Rubyize this : 5th edition</title>
    <content type="html">&lt;p&gt;Here's my take, it's short but not perfect&lt;/p&gt;

&lt;pre&gt;def highlight_text(input, words_to_highlight=%w(important monkey dancing))
  input.gsub(/#{words_to_highlight.join('|')}/i, '*\0*')
end

puts highlight_text(&amp;quot;Hey monkey, it's important you start dancing right now!&amp;quot;)
# &amp;gt;&amp;gt; Hey *monkey*, it's *important* you start *dancing* right now!

&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/203-rubyize-this-5th-edition/refactors/1339" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor1224</id>
    <published>2007-12-20T23:48:46-08:00</published>
    <title>[Ruby] On Challenge: Ugliest Ruby FizzBuzz</title>
    <content type="html">&lt;p&gt;Mine is more rubust&lt;/p&gt;

&lt;pre&gt;class FizzBuzz
class &amp;lt;&amp;lt; self
	attr_accessor :_fizzbuzz_trans_keys

end
self._fizzbuzz_trans_keys = [
	0, 0, 10, 57, 10, 57, 
	10, 57, 10, 57, 10, 
	57, 10, 57, 10, 57, 
	10, 57, 10, 57, 10, 57, 
	10, 57, 10, 57, 10, 
	57, 10, 57, 10, 57, 
	10, 57, 0
]

class &amp;lt;&amp;lt; self
	attr_accessor :_fizzbuzz_key_spans

end
self._fizzbuzz_key_spans = [
	0, 48, 48, 48, 48, 48, 48, 48, 
	48, 48, 48, 48, 48, 48, 48, 48, 
	48
]

class &amp;lt;&amp;lt; self
	attr_accessor :_fizzbuzz_index_offsets

end
self._fizzbuzz_index_offsets = [
	0, 0, 49, 98, 147, 196, 245, 294, 
	343, 392, 441, 490, 539, 588, 637, 686, 
	735
]

class &amp;lt;&amp;lt; self
	attr_accessor :_fizzbuzz_indicies

end
self._fizzbuzz_indicies = [
	0, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1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, 1, 1, 1, 1, 1, 
	1, 1, 1, 43, 38, 39, 40, 41, 
	42, 40, 41, 39, 40, 1, 25, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 26, 59, 28, 29, 
	60, 31, 29, 60, 28, 29, 1, 15, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 16, 17, 18, 
	19, 20, 21, 19, 20, 18, 19, 1, 
	0
]

class &amp;lt;&amp;lt; self
	attr_accessor :_fizzbuzz_trans_targs_wi

end
self._fizzbuzz_trans_targs_wi = [
	16, 0, 2, 4, 7, 10, 12, 15, 
	3, 2, 4, 7, 10, 12, 15, 16, 
	2, 4, 7, 10, 12, 15, 5, 9, 
	13, 3, 6, 4, 7, 10, 12, 15, 
	2, 6, 8, 14, 3, 5, 4, 9, 
	10, 12, 13, 6, 8, 7, 14, 15, 
	11, 3, 2, 4, 7, 10, 12, 15, 
	6, 8, 14, 8, 14
]

class &amp;lt;&amp;lt; self
	attr_accessor :_fizzbuzz_trans_actions_wi

end
self._fizzbuzz_trans_actions_wi = [
	1, 0, 2, 2, 2, 2, 2, 2, 
	0, 0, 0, 0, 0, 0, 0, 3, 
	4, 4, 4, 4, 4, 4, 0, 0, 
	0, 5, 5, 5, 5, 5, 5, 5, 
	5, 0, 0, 0, 6, 6, 6, 6, 
	6, 6, 6, 6, 6, 6, 6, 6, 
	6, 7, 7, 7, 7, 7, 7, 7, 
	7, 7, 7, 5, 5
]

class &amp;lt;&amp;lt; self
	attr_accessor :fizzbuzz_start
end
self.fizzbuzz_start = 1;
class &amp;lt;&amp;lt; self
	attr_accessor :fizzbuzz_first_final
end
self.fizzbuzz_first_final = 16;
class &amp;lt;&amp;lt; self
	attr_accessor :fizzbuzz_error
end
self.fizzbuzz_error = 0;

class &amp;lt;&amp;lt; self
	attr_accessor :fizzbuzz_en_main
end
self.fizzbuzz_en_main = 1;

  def initialize(data)
    @num = 1
    @data = data
    
begin
	 @p ||= 0
	 @pe ||=  @data.length
	 @cs = self.class.fizzbuzz_start
end
  end

  def execute
    parser = self
begin # ragel fflat
	_slen, _trans, _keys, _inds, _acts, _nacts = nil
	if  @p !=  @pe # pe guard
	if  @cs != 0 # errstate guard
	while true # _resume loop 
		_break_resume = false
	begin
		_break_again = false
	_keys =  @cs &amp;lt;&amp;lt; 1
	_inds = self.class._fizzbuzz_index_offsets[ @cs]
	_slen = self.class._fizzbuzz_key_spans[ @cs]
	_trans = if (   _slen &amp;gt; 0 &amp;amp;&amp;amp; 
		 self.class._fizzbuzz_trans_keys[_keys] &amp;lt;=  @data[ @p] &amp;amp;&amp;amp; 
			 @data[ @p] &amp;lt;= self.class._fizzbuzz_trans_keys[_keys + 1] 
		    ) then
		 self.class._fizzbuzz_indicies[ _inds +  @data[ @p] - self.class._fizzbuzz_trans_keys[_keys] ] 
		 else 
		 self.class._fizzbuzz_indicies[ _inds + _slen ]
		 end
	 @cs = self.class._fizzbuzz_trans_targs_wi[_trans]
	break if self.class._fizzbuzz_trans_actions_wi[_trans] == 0
	case self.class._fizzbuzz_trans_actions_wi[_trans]
	when 2
		begin
 @start_num = @p 		end
	when 6
		begin
 puts 'fizz' 		end
	when 5
		begin
 puts 'buzz' 		end
	when 1
		begin
 @start_num = @p 		end
		begin
 	begin
		_break_resume = true
		break
	end
 		end
	when 4
		begin
 puts @data[@p, @p - @start_num] 		end
		begin
 @start_num = @p 		end
	when 7
		begin
 puts 'fizz' 		end
		begin
 puts 'buzz' 		end
	when 3
		begin
 puts @data[@p, @p - @start_num] 		end
		begin
 @start_num = @p 		end
		begin
 	begin
		_break_resume = true
		break
	end
 		end
	end # action switch
	end while false # _again loop
	break if _break_resume
	break if  @cs == 0
	 @p += 1
	break if  @p ==  @pe
	end # _resume loop
	end # errstate guard
	end # pe guard
end
  end
end

if __FILE__ == $PROGRAM_NAME
  FizzBuzz.new((0..100).to_a.join(&amp;quot;\n&amp;quot;) + &amp;quot;\n&amp;quot;).execute
end&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/192-challenge-ugliest-ruby-fizzbuzz/refactors/1224" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor1000</id>
    <published>2007-12-01T20:27:31-08:00</published>
    <title>[JavaScript] On Am&#195;&#169;lioration d'une fonction JS</title>
    <content type="html">&lt;p&gt;Sorry Eineki about the problem you had editing your post, should be fixed now.&lt;/p&gt;

&lt;p&gt;Let me know if you're still having problems.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/169-amlioration-d-une-fonction-js/refactors/1000" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor920</id>
    <published>2007-11-23T15:15:35-08:00</published>
    <title>[Ruby] On managable test method</title>
    <content type="html">&lt;p&gt;might be easier for you to use Shoulda in that cause, it's plugable into your current Test::Unit::TestCase&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/159-managable-test-method/refactors/920" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor915</id>
    <published>2007-11-22T18:41:01-08:00</published>
    <title>[Ruby] On managable test method</title>
    <content type="html">&lt;p&gt;You should give a look at RSpec (&lt;a href="http://rspec.rubyforge.org/" target="_blank"&gt;http://rspec.rubyforge.org/&lt;/a&gt;) or Shoulda (&lt;a href="http://thoughtbot.com/projects/shoulda" target="_blank"&gt;http://thoughtbot.com/projects/shoulda&lt;/a&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/159-managable-test-method/refactors/915" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor914</id>
    <published>2007-11-22T18:38:17-08:00</published>
    <title>[Ruby] On fragment cache </title>
    <content type="html">&lt;p&gt;Why not used action caching ? &lt;a href="http://api.rubyonrails.org/classes/ActionController/Caching/Actions.html" target="_blank"&gt;http://api.rubyonrails.org/classes/ActionController/Caching/Actions.html&lt;/a&gt;
&lt;br /&gt;Or even better, page caching and play w/ the Expires header.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/160-fragment-cache/refactors/914" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor895</id>
    <published>2007-11-19T19:57:45-08:00</published>
    <title>[Ruby] On Random number generator</title>
    <content type="html">&lt;p&gt;Here's a fun intro to Ruby : &lt;a href="http://poignantguide.net/ruby/chapter-3.html" target="_blank"&gt;http://poignantguide.net/ruby/chapter-3.html&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/47-random-number-generator/refactors/895" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor893</id>
    <published>2007-11-19T18:09:10-08:00</published>
    <title>[Ruby] On Random number generator</title>
    <content type="html">&lt;p&gt;sorry I forgot to put the puts in the previous command ^ that's why it wasn't printing anything (fixed now)&lt;/p&gt;

&lt;p&gt;also to start the interactive terminal, type: irb not ruby&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/47-random-number-generator/refactors/893" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor891</id>
    <published>2007-11-19T15:14:04-08:00</published>
    <title>[Ruby] On Random number generator</title>
    <content type="html">&lt;p&gt;You can open an interactive shell using the irb command
&lt;br /&gt;or run a oneliner from the terminal:&lt;/p&gt;

&lt;pre&gt;ruby -e &amp;quot;puts (1..500).map {rand(10 ** 16).to_s.rjust(16,'0')}&amp;quot;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/47-random-number-generator/refactors/891" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor873</id>
    <published>2007-11-16T20:06:49-08:00</published>
    <title>[Ruby] On Handling nil object</title>
    <content type="html">&lt;p&gt;indeed, very cool Jeremy, thx a lot!&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/152-handling-nil-object/refactors/873" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor870</id>
    <published>2007-11-16T19:24:59-08:00</published>
    <title>[Ruby] On Handling nil object</title>
    <content type="html">&lt;p&gt;thx for the replies&lt;/p&gt;

&lt;p&gt;I like Jeremy solution too. But what if we want to split the category and post title w/ &amp;quot;:&amp;quot;. If there's no category, we don't want a lonely &amp;quot;:&amp;quot; on front.&lt;/p&gt;

&lt;p&gt;What do you think of:&lt;/p&gt;

&lt;pre&gt;## [html_rails]
&amp;lt;%= [@post.category.name if @post.category, link_to(@post.title, post_path(@post))].compact.join(' : ') %&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/152-handling-nil-object/refactors/870" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code152</id>
    <published>2007-11-14T02:07:08-08:00</published>
    <updated>2007-12-27T04:00:00-08:00</updated>
    <title>[Ruby] Handling nil object</title>
    <content type="html">&lt;p&gt;@post.category can be nil, or not.
&lt;br /&gt;Any cleaner way of doing this?&lt;/p&gt;

&lt;pre&gt;## [html_rails]
&amp;lt;%= (@post.category ? @post.category.name : '') + ' ' + link_to(@post.title, post_path(@post)) %&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/152-handling-nil-object" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor745</id>
    <published>2007-11-05T22:24:51-08:00</published>
    <title>[Ruby] On resource_controller: Redesign My API</title>
    <content type="html">&lt;p&gt;A couple of suggestions. I'm used to the default respond_to rather then wants. And I don't know if the *_finder macros are even possible, but would look like a true dsl&lt;/p&gt;

&lt;pre&gt;## Before / After / Response

class PostsController &amp;lt; ApplicationController
  acts_as_resource_controller

  # block syntax
  create do
    before { @post.user = current_user }
    respond_to do |format|
      format.html
      format.js
    end
  end
  
  # chain syntax
  update.failure.respond_to %w(js html)
end

## Alternate find syntax

class PostsController &amp;lt; ResourceController::Base
  object_finder :find_by_permalink
  collection_finder { find :all, :page =&amp;gt; {:current =&amp;gt; params[:page], :size =&amp;gt; 10} }
end
&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/137-resource_controller-redesign-my-api/refactors/745" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor654</id>
    <published>2007-10-30T15:53:02-07:00</published>
    <title>[Ruby] On Is This String Postal?</title>
    <content type="html">&lt;p&gt;I think {1} are useless, we also can make it case insensitive&lt;/p&gt;

&lt;pre&gt;class String 
  def postal?  
    self =~ /[a-z]\d[a-z]([\s-])*\d[a-z]\d/i
 end
end
&lt;/pre&gt;</content>
    <author>
      <name>macournoyer</name>
      <email>macournoyer@yahoo.ca</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/118-is-this-string-postal/refactors/654" rel="alternate"/>
  </entry>
</feed>

