<?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:users237</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/237" rel="self"/>
  <title>jswanner</title>
  <updated>Thu Apr 17 13:53:21 -0700 2008</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor5203</id>
    <published>2008-04-17T13:53:21-07:00</published>
    <title>[Ruby] On Rubyize this : 6th edition</title>
    <content type="html">&lt;p&gt;not much different than what has already been submitted.&lt;/p&gt;

&lt;pre&gt;class VotingSystem  
  @@votes = {  &amp;quot;yes, it sucks&amp;quot; =&amp;gt;  0, &amp;quot;no, it doesn't suck&amp;quot; =&amp;gt; 0, &amp;quot;other&amp;quot;  =&amp;gt; 0}

  def cast_vote(vote)
    @@votes[vote.downcase] += 1
  rescue
    @@votes['other'] += 1
  end

  def results 
    @@votes.each do |vote, count|
      puts &amp;quot;there are #{count} vote(s) for '#{vote}'&amp;quot;
    end
  end
end
&lt;/pre&gt;</content>
    <author>
      <name>jswanner</name>
      <email>jacob@jacobswanner.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/283-rubyize-this-6th-edition/refactors/5203" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor514</id>
    <published>2007-10-23T14:27:15-07:00</published>
    <title>[Ruby] On Rubyize this : 4th edition</title>
    <content type="html">

&lt;pre&gt;class Bug
  attr_accessor :type, :name, :iq, :annoyance_factor

  def initialize(name=&amp;quot;unnamed&amp;quot;, type=&amp;quot;spider&amp;quot;, iq=8, annoyance_factor=4)
    @type = type
    @name = name
    @iq = iq
    @annoyance_factor = annoyance_factor
  end

  #works with keep_type or keep_types, things like keep_butterflies does not work
  def Bug.method_missing(name, args)
    name = name.to_s
    if (name =~ /^keep_([a-z]+?)s?$/i)
      bugs = args.select{ |bug| bug.type == $1 }
    end
  end
end

bugs = [
  Bug.new(&amp;quot;ron&amp;quot;,&amp;quot;spider&amp;quot;,&amp;quot;4&amp;quot;,&amp;quot;2&amp;quot;),
  Bug.new(&amp;quot;don&amp;quot;,&amp;quot;spider&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;3&amp;quot;),
  Bug.new(&amp;quot;jake&amp;quot;,&amp;quot;ant&amp;quot;,&amp;quot;9&amp;quot;,&amp;quot;4&amp;quot;),
  Bug.new(&amp;quot;chris&amp;quot;,&amp;quot;ladybug&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;4&amp;quot;),
  Bug.new(&amp;quot;fred&amp;quot;,&amp;quot;cockchaffer&amp;quot;,&amp;quot;0&amp;quot;,&amp;quot;5&amp;quot;),
  Bug.new(&amp;quot;greg&amp;quot;,&amp;quot;butterfly&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;0&amp;quot;),
  Bug.new(&amp;quot;jason&amp;quot;,&amp;quot;butterfly&amp;quot;,&amp;quot;0&amp;quot;,&amp;quot;2&amp;quot;)
]

butterflies = Bug.keep_butterfly(bugs)

butterflies.each do |b|
  puts &amp;quot;I am #{b.name}, a beautiful #{b.type}.  I have an IQ of #{b.iq} and an annoyance factor of #{b.annoyance_factor}&amp;quot;
end&lt;/pre&gt;</content>
    <author>
      <name>jswanner</name>
      <email>jacob@jacobswanner.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/99-rubyize-this-4th-edition/refactors/514" rel="alternate"/>
  </entry>
</feed>

