<?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:users1066friends</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/1066/friends" rel="self"/>
  <title>seaofclouds friends</title>
  <updated>Wed Sep 17 18:54:34 +0000 2008</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor18376</id>
    <published>2008-09-17T18:54:34+00:00</published>
    <title>[C] On A Java-like function split</title>
    <content type="html">

&lt;pre&gt;## split.h
#ifndef _SPLIT_H_
#define _SPLIT_H_

char * string_create(char *start, char *end);
char ** split(char *string, char seperator, char escape);

#endif

## split.c
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;array.h&amp;quot;

char * string_create(char *start, char *end)
{
    char *result = malloc(sizeof(char) * (end - start + 1));

    strncpy(result, start, end - start);
    
    return result;
}

char ** split(char *string, char seperator, char escape)
{
    char **result;
    int escape_count = 0;
    char *string_offset = string;
    char seperation_character = seperator;
    Array *array = array_init();
    
    while (*string++) {
        if (*string == escape) {
            escape_count++;
            seperation_character = escape;
        }
        
        if (*string == seperation_character || *string == '\0') {
            array_push(array, string_create(string_offset, string));
            string_offset = string + 1;
            
            if (escape_count &amp;gt; 1) {
                escape_count--;
                seperation_character = seperator;
            }
        }
    }
    
    result = array_to_char_array(array);
    array_free(array);    
    
    return result;
}

## array.h
#ifndef _ARRAY_H_
#define _ARRAY_H_

typedef struct _array {
    char **elements;
    int size;
} Array;

Array * array_init();
Array * array_push(Array *array, char *value);
char ** array_to_char_array(Array *array);
void array_free(Array *array);

#endif

## array.c
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;array.h&amp;quot;

Array * array_init()
{
    Array *array = malloc(sizeof(Array));

    array-&amp;gt;elements = NULL;
    array-&amp;gt;size = 0;
    
    return array;
}

Array * array_push(Array *array, char *value)
{
    array-&amp;gt;elements = realloc(array-&amp;gt;elements, sizeof(char *) * ++array-&amp;gt;size);
    array-&amp;gt;elements[array-&amp;gt;size - 1] = value;
    
    return array;
}

char ** array_to_char_array(Array *array)
{
    char **result = malloc(sizeof(char *) * array-&amp;gt;size + 1);
    
    memcpy(result, array-&amp;gt;elements, sizeof(char *) * array-&amp;gt;size);
    
    return result;
}

void array_free(Array *array)
{
    free(array-&amp;gt;elements);
    free(array);
}&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/494-a-java-like-function-split/refactors/18376" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor18163</id>
    <published>2008-09-17T16:34:07+00:00</published>
    <title>[Ruby] On Horrible loop</title>
    <content type="html">

&lt;pre&gt;@feedbacks.each do |feedback|
  data.each do |key,value|
    question = feedback.send(&amp;quot;question#{key + 1}&amp;quot;)
    value[question.to_i - 1] += 1 if question
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/495-horrible-loop/refactors/18163" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor16507</id>
    <published>2008-09-05T18:59:27+00:00</published>
    <title>[Ruby] On sort_by_multiple</title>
    <content type="html">&lt;p&gt;Are you using Ruby 1.9 by any chance? Otherwise you should be getting an OrderedHash. Here's the relevant code from ActiveSupport:&lt;/p&gt;

&lt;pre&gt;module Enumerable
  # Ruby 1.8.7 introduces group_by, but the result isn't ordered. Override it.
  remove_method(:group_by) if [].respond_to?(:group_by) &amp;amp;&amp;amp; RUBY_VERSION &amp;lt; '1.9'
 
  def group_by
    inject ActiveSupport::OrderedHash.new do |grouped, element|
      (grouped[yield(element)] ||= []) &amp;lt;&amp;lt; element
      grouped
    end
  end unless [].respond_to?(:group_by)

  ...&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/482-sort_by_multiple/refactors/16507" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor16502</id>
    <published>2008-09-05T18:11:13+00:00</published>
    <title>[Ruby] On sort_by_multiple</title>
    <content type="html">&lt;p&gt;That error is normal under that circumstance. OrderedHash works with arrays, not hashes.&lt;/p&gt;

&lt;p&gt;&amp;gt;&amp;gt; ActiveSupport::OrderedHash.new([[1,2], [3,4]])     
&lt;br /&gt;=&amp;gt; [[1, 2], [3, 4]]&lt;/p&gt;

&lt;p&gt;However, there shouldn't be a Hash going into the class from the specs you posted.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/482-sort_by_multiple/refactors/16502" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor16497</id>
    <published>2008-09-05T17:29:03+00:00</published>
    <title>[Ruby] On sort_by_multiple</title>
    <content type="html">&lt;p&gt;How strange. It passes all your specs here. Using ActiveSupport 2.1 and Ruby 1.8.5.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/482-sort_by_multiple/refactors/16497" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor16489</id>
    <published>2008-09-05T15:57:49+00:00</published>
    <title>[Ruby] On sort_by_multiple</title>
    <content type="html">&lt;p&gt;This is quite a bit faster on my system.&lt;/p&gt;

&lt;pre&gt;## Sorter
require &amp;quot;activesupport&amp;quot;

class Sorter &amp;lt; ActiveSupport::OrderedHash
  def initialize(array, &amp;amp;block)
    block ||= lambda { |element| element }
    super(array.map { |element| block.call(element).clone }.group_by { |element| element.delete_at(0) })
  end
  
  def sort(*directions)
    keys.sort(&amp;amp;method(directions.shift)).inject([]) do |result,key|
      next [ result, key ].flatten if self[key].flatten.empty?
      
      Sorter.new(self[key]).sort(*directions).each do |array|
        result &amp;lt;&amp;lt; [ key, *array ].flatten
      end
      
      result
    end
  end
  
  private
    def ascending(a, b)
      a &amp;lt;=&amp;gt; b
    end
    
    def descending(a, b)
      b &amp;lt;=&amp;gt; a
    end
end

## Enumerable
module Enumerable
  def sort_by_multiple(*directions, &amp;amp;block)
    Sorter.new(self, &amp;amp;block).sort(*directions)
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/482-sort_by_multiple/refactors/16489" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor16323</id>
    <published>2008-09-03T16:21:26+00:00</published>
    <title>[Ruby] On Rails Active Record Time Summary </title>
    <content type="html">&lt;p&gt;This is completely untested since I don't have a good environment to play in, but this should hopefully give you a pretty good idea of where you can go with this. Use mixins if you are performing the same operation on more than one model.&lt;/p&gt;

&lt;pre&gt;class Summary &amp;lt; Struct.new(:klass, :options)
  def range
    options[:range] || options[:from]..options[:to]
  end
  
  def step
    options[:step]
  end

  def calculate(method, *args)
    klass.between(range).by_timestamp(step).send(method, *args)
  end
  
  def method_missing(method, *args, &amp;amp;block)
    records = Hash[calculate(method, *args).map(&amp;amp;:reverse).flatten]
    range.map { |time| records[time.to_i].to_f }
  end
end
    
class Order &amp;lt; ActiveRecord::Base
  named_scope :between, lambda { |range| { :conditions =&amp;gt; { :created_at =&amp;gt; range } } }
  named_scope :by_timestamp, lambda { |step| { :group =&amp;gt; &amp;quot;round(UNIX_TIMESTAMP(created_at)/#{step})&amp;quot; } }
  
  def self.summary(options)
    Summary.new(self, options)
  end
end    

# Example usage:
#
# Order.summary(:from =&amp;gt; Time.now, :to =&amp;gt; 6.hours.from_now, :step =&amp;gt; 10).sum(:amount)
# Order.summary(:from =&amp;gt; Time.now, :to =&amp;gt; 6.hours.from_now, :step =&amp;gt; 10).count(:amount)&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/479-rails-active-record-time-summary/refactors/16323" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor16292</id>
    <published>2008-09-03T05:14:34+00:00</published>
    <title>[Ruby] On A Rails rake task to lookup status codes.</title>
    <content type="html">

&lt;pre&gt;task :status_codes do
  require 'action_controller/status_codes'
  include ActionController::StatusCodes  
  
  SYMBOL_TO_STATUS_CODE.sort_by(&amp;amp;:last).map do |symbol,status|    
    &amp;quot;%-4s :%-32s %s\n&amp;quot; % [ status, symbol, STATUS_CODES[status] ]
  end.grep(/(^|:)#{ENV['CODE'] || ENV['code']}/i).display
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/463-a-rails-rake-task-to-lookup-status-codes/refactors/16292" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor16013</id>
    <published>2008-08-29T21:11:06+00:00</published>
    <title>[Ruby] On Too many assignments and conditional statements</title>
    <content type="html">&lt;p&gt;Edit: Double post.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/466-too-many-assignments-and-conditional-statements/refactors/16013" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor16012</id>
    <published>2008-08-29T21:03:20+00:00</published>
    <title>[Ruby] On Too many assignments and conditional statements</title>
    <content type="html">&lt;p&gt;I couldn't quite discern what exactly you are trying to do. I'm guessing there is a much better way to do it. But based on what I could gather:&lt;/p&gt;

&lt;pre&gt;class Commentor
  def comment_type
    self.class.to_s.downcase
  end
  
  def comment
    comments.find_by_comment_type(comment_type)
  end
  
  def build_comment(*args)
    comments.build(*args)
  end
  
  def add_comment(text)
    if comment
      comment.text += text
    else
      build_comment(:text =&amp;gt; text, :comment_type =&amp;gt; comment_type)
    end
  end
end

class Header &amp;lt; ActiveRecord::Base
  include Commentor
  has_many :comments
end

class Project &amp;lt; ActiveRecord::Base
  include Commentor
  has_one :comment
end

class Comment &amp;lt; ActiveRecord::Base
  belongs_to :header
  belongs_to :traslation
end

# Usage:
# translation.add_comment(&amp;quot;This is a comment&amp;quot;)&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/466-too-many-assignments-and-conditional-statements/refactors/16012" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15934</id>
    <published>2008-08-28T22:02:18+00:00</published>
    <title>[Ruby] On Code to detect the web browser</title>
    <content type="html">&lt;p&gt;@Nicol&#225;s - I don't think the detect method does what you think it does. You can do the following, but I decided I liked the other form better.&lt;/p&gt;

&lt;pre&gt;def test_web_browser
  %w(Firefox/3 Firefox/2 MSIE\ 6 MSIE\ 7 Opera).detect do |agent|
    request.user_agent =~ Regexp.new(agent)
  end.gsub(/\W+/, &amp;quot;&amp;quot;)
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/462-code-to-detect-the-web-browser/refactors/15934" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15923</id>
    <published>2008-08-28T18:50:37+00:00</published>
    <title>[Ruby] On simplify multiple gsub</title>
    <content type="html">

&lt;pre&gt;class Normalizer &amp;lt; Struct.new(:string)
  REPLACEMENTS = {
    0x92 =&amp;gt; &amp;quot;&amp;amp;#39;&amp;quot;,
    0x91 =&amp;gt; &amp;quot;&amp;amp;#39;&amp;quot;,
    0x96 =&amp;gt; &amp;quot;-&amp;quot;,
    0xAE =&amp;gt; &amp;quot;(R)&amp;quot;,
    0x99 =&amp;gt; &amp;quot;(TM)&amp;quot;,
    0xBD =&amp;gt; &amp;quot;1/2&amp;quot;,
    0xBE =&amp;gt; &amp;quot;3/4&amp;quot;,
    0xBC =&amp;gt; &amp;quot;1/4&amp;quot;,
    0xB0 =&amp;gt; &amp;quot; degree &amp;quot;,
    0xBA =&amp;gt; &amp;quot; degrees &amp;quot;
  }
  
  def normalize
    string.enum_for(:each_byte).map { |char| REPLACEMENTS[char] || char.chr }.join
  end
  
  def normalize!
    string.replace(normalize)
  end
end

# Normalizer.new(data).normalize!&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/459-simplify-multiple-gsub/refactors/15923" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15921</id>
    <published>2008-08-28T18:32:22+00:00</published>
    <title>[Ruby] On Code to detect the web browser</title>
    <content type="html">

&lt;pre&gt;def test_web_browser
  catch(:match) do
    [&amp;quot;Firefox/3&amp;quot;, &amp;quot;Firefox/2&amp;quot;, &amp;quot;MSIE 6&amp;quot;, &amp;quot;MSIE 7&amp;quot;, &amp;quot;Opera&amp;quot;].each do |ua|
      throw(:match, ua.gsub(/[^a-z0-9]/i, &amp;quot;&amp;quot;)) if request.user_agent =~ Regexp.new(ua)
    end
    nil
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/462-code-to-detect-the-web-browser/refactors/15921" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15821</id>
    <published>2008-08-27T13:42:51+00:00</published>
    <title>[Ruby] On simplify multiple gsub</title>
    <content type="html">&lt;p&gt;Perhaps I wasn't clear with my previous post. The normalize method does the same thing you are doing with gsub.&lt;/p&gt;

&lt;pre&gt;&amp;quot;\xBD + \xBC&amp;quot;.chars.normalize.to_s
=&amp;gt; &amp;quot;1/2 + 1/4&amp;quot;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/459-simplify-multiple-gsub/refactors/15821" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15802</id>
    <published>2008-08-27T04:07:04+00:00</published>
    <title>[Ruby] On simplify multiple gsub</title>
    <content type="html">&lt;p&gt;Why not use ActiveSupport::Multibyte::Chars instead?&lt;/p&gt;

&lt;pre&gt;data.chars.normalize!

&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/459-simplify-multiple-gsub/refactors/15802" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15380</id>
    <published>2008-08-20T14:06:04+00:00</published>
    <title>[Ruby] On Code transactions</title>
    <content type="html">

&lt;pre&gt;require 'transaction/simple/group'

def transact(objects, action)
  group = Transaction::Simple::Group.new(*objects)
  group.start_transaction
  
  if objects.all? { |object| object.send(action) }
    group.commit_transaction
  else
    group.abort_transaction
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/452-code-transactions/refactors/15380" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15378</id>
    <published>2008-08-20T13:51:49+00:00</published>
    <title>[Ruby] On Link to if else simple condition.</title>
    <content type="html">&lt;p&gt;You should be using named routes, not hashes, for URLs. After you change that it won't be so bad to have just a plain old if statement in your view.&lt;/p&gt;

&lt;pre&gt;## View [html_rails]
&amp;lt;span class=&amp;quot;bluelinks-allsmall&amp;quot;&amp;gt;
	&amp;lt;% if user.normal? %&amp;gt;
		&amp;lt;%= link_to &amp;quot;Normal&amp;quot;, formatted_howto_path(howto, :normal) %&amp;gt;
	&amp;lt;% else %&amp;gt;
		&amp;lt;%= link_to &amp;quot;Executive&amp;quot;, formatted_howto_path(howto, :executive) %&amp;gt;
	&amp;lt;% end %&amp;gt;
&amp;lt;/span&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/453-link-to-if-else-simple-condition/refactors/15378" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15352</id>
    <published>2008-08-20T05:21:15+00:00</published>
    <title>[Ruby] On Method for sorting</title>
    <content type="html">&lt;p&gt;Here is your sort algorithm refactored in a more Ruby-like fashion. Hopefully it makes it much clearer as to what is going on.&lt;/p&gt;

&lt;pre&gt;def sort(array)
  array.inject([]) do |sorted,element|
    small, large = sorted.partition { |item| item &amp;lt; element }
    (small &amp;lt;&amp;lt; element) + large
  end
end

&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/449-method-for-sorting/refactors/15352" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15348</id>
    <published>2008-08-20T04:22:14+00:00</published>
    <title>[Ruby] On Default value for user column</title>
    <content type="html">&lt;p&gt;I disagree with the others that it belongs in the model. This is most certainly display logic and would traditionally belong in a helper method. Except helper methods are rather ugly for this kind of thing. Thus, I give you a (basic) presenter:&lt;/p&gt;

&lt;pre&gt;## Helper
module ApplicationHelper
  def present(object)
    object.class.const_get(&amp;quot;Presenter&amp;quot;).new(object)
  end
end

## Presenter
class User::Presenter &amp;lt; Struct.new(:user)
  def city
    user.city.blank? ? &amp;quot;Not specified&amp;quot; : user.city.capitalize
  end
  
  def method_missing(method, *args, &amp;amp;block)
    user.send(method, *args, &amp;amp;block)
  end
end

## View [html_rails]
&amp;lt;%= present(@user).city %&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/446-default-value-for-user-column/refactors/15348" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15312</id>
    <published>2008-08-19T17:43:24+00:00</published>
    <title>[Ruby] On Method for sorting</title>
    <content type="html">&lt;p&gt;Although I understand that you are probably trying to learn the logic behind sorting, Ruby has it's own built-in sort method. So, from a refactoring point of view, all you need is something like this:&lt;/p&gt;

&lt;pre&gt;puts &amp;quot;Enter words, blank row quits.&amp;quot;        

while !(line = gets.chomp).empty?
  (lines ||= []) &amp;lt;&amp;lt; line
end

puts &amp;quot;sorted: #{lines.sort}&amp;quot;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/449-method-for-sorting/refactors/15312" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15306</id>
    <published>2008-08-19T15:43:59+00:00</published>
    <title>[Ruby] On How to benchmark</title>
    <content type="html">&lt;p&gt;Use script/performance/benchmarker to call each version. However, I would suggest that you only worry about the quality of the code here. The performance differences will be negligible.&lt;/p&gt;

&lt;p&gt;Also, I present to you an additional refactoring:&lt;/p&gt;

&lt;pre&gt;def self.favorite?(object)
  if reflection = object.class.reflect_on_association(:favorites)
    send(&amp;quot;find_by_#{reflection.primary_key_name}&amp;quot;, object)
  end
end

# Example usage:
# script/performance/benchmarker 50 &amp;quot;User.first.favorites.favorite?(Yellowpage.first)&amp;quot;&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/445-how-to-benchmark/refactors/15306" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15301</id>
    <published>2008-08-19T14:16:03+00:00</published>
    <title>[Ruby] On simple pluralize</title>
    <content type="html">

&lt;pre&gt;&amp;lt;%= pluralize(@resource.favorites.length, &amp;quot;Favorite&amp;quot;) %&amp;gt; &lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/444-simple-pluralize/refactors/15301" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15091</id>
    <published>2008-08-15T13:23:37+00:00</published>
    <title>[Ruby] On CSV turn in to an array of hashes</title>
    <content type="html">

&lt;pre&gt;require &amp;quot;csv&amp;quot;
require &amp;quot;enumerator&amp;quot;

def fix_send_to_array(recipients)
  CSV.parse_line(recipients).enum_slice(2).map do |name,email|
    { &amp;quot;name&amp;quot; =&amp;gt; name, &amp;quot;email&amp;quot; =&amp;gt; email }
  end
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/437-csv-turn-in-to-an-array-of-hashes/refactors/15091" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15044</id>
    <published>2008-08-14T20:13:05+00:00</published>
    <title>[Ruby] On A shorter way to declare class constants?</title>
    <content type="html">

&lt;pre&gt;class Report &amp;lt; ActiveRecord::Base
  %w[hits uniques].each { |const| const_set(const.upcase, const) }
end&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/436-a-shorter-way-to-declare-class-constants/refactors/15044" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor15025</id>
    <published>2008-08-14T14:03:15+00:00</published>
    <title>[Ruby] On Split an array into half</title>
    <content type="html">

&lt;pre&gt;require &amp;quot;enumerator&amp;quot;

artists = [ 1, 2, 3 ]
column_1, column_2 = artists.enum_slice((artists.size / 2.0).round).to_a&lt;/pre&gt;</content>
    <author>
      <name>Adam</name>
      <email>skidooer+p@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/435-split-an-array-into-half/refactors/15025" rel="alternate"/>
  </entry>
</feed>
