<?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:users184</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/184" rel="self"/>
  <title>FrankLamontagne</title>
  <updated>Thu Apr 17 13:13:21 -0700 2008</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor5201</id>
    <published>2008-04-17T13:13:21-07:00</published>
    <title>[Ruby] On Rubyize this : 6th edition</title>
    <content type="html">&lt;p&gt;Here is my solution... nothing revolutionary but it does the job. I also added the possibility to vote on multiple questions&lt;/p&gt;

&lt;pre&gt;class VotingSystem
  def vote(answer, question = &amp;quot;is 'the flinstones' a boring t.v. show?&amp;quot;)				
    if @@votes.has_key?(question.downcase) &amp;amp;&amp;amp; @@votes[question.downcase].has_key?(answer.downcase)
      @@votes[question][answer.downcase] += 1
      puts &amp;quot;There are #{@@votes[question.downcase][answer.downcase]-1} people who think like you!&amp;quot;
    else
      puts &amp;quot;Inexistant question or answer&amp;quot;
    end		
  end	
	
  private
  @@votes =  {	
    &amp;quot;is 'the flinstones' a boring t.v. show?&amp;quot; =&amp;gt; {&amp;quot;yes, it sucks!&amp;quot; =&amp;gt; 0, &amp;quot;no, it rocks!&amp;quot; =&amp;gt; 0},
    &amp;quot;what is your name?&amp;quot; =&amp;gt; {&amp;quot;frank&amp;quot; =&amp;gt; 0, &amp;quot;what's the point to vote on that?&amp;quot; =&amp;gt; 0}		
  }	
end&lt;/pre&gt;</content>
    <author>
      <name>FrankLamontagne</name>
      <email>contact@francoislamontagne.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/283-rubyize-this-6th-edition/refactors/5201" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code283</id>
    <published>2008-04-17T00:20:48-07:00</published>
    <updated>2008-09-16T14:49:49-07:00</updated>
    <title>[Ruby] Rubyize this : 6th edition</title>
    <content type="html">&lt;p&gt;Ouch... this guy badly needs (but doesn't deserve) help! Original article on RubyFleebie is here : &lt;a href="http://www.rubyfleebie.com/rubyize-this-6th-edition" target="_blank"&gt;http://www.rubyfleebie.com/rubyize-this-6th-edition&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;class VotingSystem  
  #Hello, I am Rodger the old and unhappy programmer. the variable nbrOfVotes is an array of 2 dimensions. The first dimension contains the number of votes for the answer &amp;quot;YES, IT SUCKS&amp;quot;... and the other dimension contain the number of votes for the answer &amp;quot;NO, IT DOESN'T SUCK&amp;quot;. In the near future there will be other possible answers... but I don't care! I retire in 2 days!
  @@nbrOfVotes = Array.new
  
  #The users who sent their vote arrive in this very top secret method!! (I retire in 2 days!)
  def receiveAVote(theVote)
    if theVote == &amp;quot;YES, IT SUCKS&amp;quot;
     @@nbrOfVotes[0] = 0 if @@nbrOfVotes[0].nil?
     @@nbrOfVotes[0] = @@nbrOfVotes[0] + 1
    else
      if theVote == &amp;quot;NO, IT DOESN'T SUCK&amp;quot;
        @@nbrOfVotes[1] = 0 if @@nbrOfVotes[1].nil?
        @@nbrOfVotes[1] = @@nbrOfVotes[1] + 1
      else
          puts &amp;quot;THIS IS NOT A VALID ANSWER YOU MORON... btw i retire in 2 days!&amp;quot;
      end
    end
  end

  #This is the function that compile ALL the votes... I retire in 2 days!
  def compileAllTheVotes
    for i in (0..1)
      if i == 0
        @@nbrOfVotes[0] = 0 if @@nbrOfVotes[0].nil?
        puts &amp;quot;HERE IS THE NUMBER OF VOTES FOR 'YES IT SUCKS' : &amp;quot; + @@nbrOfVotes[0].to_s
      else
        if i == 1
          @@nbrOfVotes[1] = 0 if @@nbrOfVotes[1].nil?
          puts &amp;quot;HERE IS THE NUMBER OF VOTES FOR 'NO IT DOESN'T SUCKS' : &amp;quot; + @@nbrOfVotes[1].to_s
        end
     end
    end
  end
end&lt;/pre&gt;</content>
    <author>
      <name>FrankLamontagne</name>
      <email>contact@francoislamontagne.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/283-rubyize-this-6th-edition" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code203</id>
    <published>2008-01-03T13:33:19-08:00</published>
    <updated>2008-09-16T14:49:29-07:00</updated>
    <title>[Ruby] Rubyize this : 5th edition</title>
    <content type="html">&lt;p&gt;Here is the 5th edition of Rubyize this. You can find the original blog post on ruby fleebie here : &lt;a href="http://www.rubyfleebie.com/rubyize-this-5th-edition/" target="_blank"&gt;http://www.rubyfleebie.com/rubyize-this-5th-edition/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tom wrote a very simple ruby script to highlight some words in a text. He chose to highlight the words with asterisks, like *that* (In 2 months, perhaps Tom will have to use his script to produce HTML output or something else... he will be screwed with those basic asterisks). Tom has absolutely no ruby background, help him refactor his code &amp;lt;em&amp;gt;ala&amp;lt;/em&amp;gt; Ruby, that is : short, clean and simple.&lt;/p&gt;

&lt;p&gt;By the way, Tom didn't put a lot of effort in his algorithm. His dumb gsub thing will mistakenly replace &amp;lt;em&amp;gt;parts of words&amp;lt;/em&amp;gt; instead of whole words only. Maybe some improvements would be needed there.&lt;/p&gt;

&lt;pre&gt;@wordsToHighlight=[&amp;quot;important&amp;quot;,&amp;quot;monkey&amp;quot;,&amp;quot;dancing&amp;quot;]
def highlightText(input)
  for i in 0..@wordsToHighlight.length-1 do
    input = input.gsub(@wordsToHighlight[i],&amp;quot;*&amp;quot; + @wordsToHighlight[i] + &amp;quot;*&amp;quot;)
  end
  return input
end&lt;/pre&gt;</content>
    <author>
      <name>FrankLamontagne</name>
      <email>contact@francoislamontagne.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/203-rubyize-this-5th-edition" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor515</id>
    <published>2007-10-23T14:28:15-07:00</published>
    <title>[Ruby] On Rubyize this : 4th edition</title>
    <content type="html">

&lt;pre&gt;class Bug
  attr_accessor :name,:type,:iq,:annoyance_factor
  def initialize(name=&amp;quot;unname&amp;quot;,type=:spider,iq=8,annoyance_factor=4)
	@name=name
	@type=type
	@iq=iq
	@annoyance_factor=annoyance_factor
  end  
end

class Bugs &amp;lt; Array
  def keep(type)
    self.reject! { |b| b.type != type }
  end
  
  def talk!
    self.each do |bug|
      puts &amp;quot;I am a #{bug.type.to_s} and my name is #{bug.name}. I have an IQ of #{bug.iq} and an annoyance factor of #{bug.annoyance_factor}&amp;quot;
    end
  end
end

bugs = Bugs.new([
  Bug.new(&amp;quot;ron&amp;quot;,:spider,4,2),
  Bug.new(&amp;quot;don&amp;quot;,:spider,2,3),
  Bug.new(&amp;quot;jake&amp;quot;,:ant,9,4),
  Bug.new(&amp;quot;chris&amp;quot;,:ladybug,2,4),
  Bug.new(&amp;quot;fred&amp;quot;,:cockchaffer,0,5),
  Bug.new(&amp;quot;greg&amp;quot;,:butterfly,2,0),
  Bug.new(&amp;quot;jason&amp;quot;,:butterfly,0,2)
])

bugs.keep(:butterfly)
bugs.talk!&lt;/pre&gt;</content>
    <author>
      <name>FrankLamontagne</name>
      <email>contact@francoislamontagne.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/99-rubyize-this-4th-edition/refactors/515" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code99</id>
    <published>2007-10-23T12:26:05-07:00</published>
    <updated>2008-09-16T14:49:35-07:00</updated>
    <title>[Ruby] Rubyize this : 4th edition</title>
    <content type="html">&lt;p&gt;Welcome to the 4th edition of Rubyize this! (&lt;a href="http://www.rubyfleebie.com/rubyize-this-4th-edition" target="_blank"&gt;http://www.rubyfleebie.com/rubyize-this-4th-edition&lt;/a&gt;) I have an array of insects and I want to be able to display the name, the iq and the annoyance factor of every members of a certain type. This &amp;quot;solution&amp;quot; works but has a ruby rating of 0.5/5. Moreover, it only works for butterflies... which feels rather incomplete and limiting. Remove stuff, add stuff and move stuff around. This dumb code must get smart and pretty!&lt;/p&gt;

&lt;pre&gt;class Bug
	attr_accessor :type
	attr_accessor :name
	attr_accessor :iq
	attr_accessor :annoyance_factor	
	
	def initialize(name,type,iq,annoyance_factor)
		if !type
			@type=&amp;quot;spider&amp;quot;
		else
			@type=type
		end
		
		if !name
			@name=&amp;quot;unnamed&amp;quot;
		else
			@name=name
		end		
		
		if !iq
			@iq = 8
		else
			@iq = iq
		end
		
		if !annoyance_factor
			@annoyance_factor = 4
		else
			@annoyance_factor = annoyance_factor
		end	
	end	
end

def keep_butterflies(bugs)
	butterflies = Array.new
	bugs.each do |bug|
		if bug.type == &amp;quot;butterfly&amp;quot;
			butterflies.push(bug)
		end
	end	
	return butterflies
end

#create some bugs!
bugs = Array.new
bugs.push(Bug.new(&amp;quot;ron&amp;quot;,&amp;quot;spider&amp;quot;,&amp;quot;4&amp;quot;,&amp;quot;2&amp;quot;))
bugs.push(Bug.new(&amp;quot;don&amp;quot;,&amp;quot;spider&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;3&amp;quot;))
bugs.push(Bug.new(&amp;quot;jake&amp;quot;,&amp;quot;ant&amp;quot;,&amp;quot;9&amp;quot;,&amp;quot;4&amp;quot;))
bugs.push(Bug.new(&amp;quot;chris&amp;quot;,&amp;quot;ladybug&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;4&amp;quot;))
bugs.push(Bug.new(&amp;quot;fred&amp;quot;,&amp;quot;cockchaffer&amp;quot;,&amp;quot;0&amp;quot;,&amp;quot;5&amp;quot;))
bugs.push(Bug.new(&amp;quot;greg&amp;quot;,&amp;quot;butterfly&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;0&amp;quot;))
bugs.push(Bug.new(&amp;quot;jason&amp;quot;,&amp;quot;butterfly&amp;quot;,&amp;quot;0&amp;quot;,&amp;quot;2&amp;quot;))

butterflies=keep_butterflies(bugs)

butterflies.each do |butterfly|
	puts &amp;quot;I am a butterfly and my name is #{butterfly.name}. I have an IQ of #{butterfly.iq} and an annoyance factor of #{butterfly.annoyance_factor}&amp;quot;
end&lt;/pre&gt;</content>
    <author>
      <name>FrankLamontagne</name>
      <email>contact@francoislamontagne.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/99-rubyize-this-4th-edition" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor376</id>
    <published>2007-10-11T16:40:49-07:00</published>
    <title>[Ruby] On Rubyize this : 3rd edition</title>
    <content type="html">&lt;p&gt;A reversed approach...&lt;/p&gt;

&lt;pre&gt;def remove_insults(input)
  insults = [&amp;quot;stupid&amp;quot;,&amp;quot;moron&amp;quot;,&amp;quot;dumbass&amp;quot;,&amp;quot;retard&amp;quot;]
  insults.each { |insult| input.gsub!(insult,'*' * insult.length) }
  input
end 
puts remove_insults(&amp;quot;You truly are a moron sir!&amp;quot;)&lt;/pre&gt;</content>
    <author>
      <name>FrankLamontagne</name>
      <email>contact@francoislamontagne.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/74-rubyize-this-3rd-edition/refactors/376" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code74</id>
    <published>2007-10-11T15:21:49-07:00</published>
    <updated>2008-09-30T20:41:30-07:00</updated>
    <title>[Ruby] Rubyize this : 3rd edition</title>
    <content type="html">&lt;p&gt;This snippet is coming from the serie &amp;quot;Rubyize this&amp;quot; you can find on Ruby Fleebie ( &lt;a href="http://www.rubyfleebie.com/rubyize-this-3rd-edition" target="_blank"&gt;http://www.rubyfleebie.com/rubyize-this-3rd-edition&lt;/a&gt;)
&lt;br /&gt;It's poorly written on purpose! The objective is to let people improve it and make it looks more ruby-like.&lt;/p&gt;

&lt;pre&gt;def remove_insults(input)
   ctr = 0
   input.each do |word|
     word = word.downcase
     if word == &amp;quot;stupid&amp;quot; || word == &amp;quot;moron&amp;quot; || word == &amp;quot;dumbass&amp;quot; || word == &amp;quot;retard&amp;quot;
       i=0
       word.length.times do
          input[ctr][i,1] = &amp;quot;*&amp;quot;
          i+=1
       end
     end
     ctr += 1
   end

   puts input.join(&amp;quot; &amp;quot;).to_s
end

remove_insults &amp;quot;you truly are a moron sir!&amp;quot;.split(&amp;quot; &amp;quot;)&lt;/pre&gt;</content>
    <author>
      <name>FrankLamontagne</name>
      <email>contact@francoislamontagne.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/74-rubyize-this-3rd-edition" rel="alternate"/>
  </entry>
</feed>

