Rubyize this : 3rd edition

It’s time for another phenomenal edition of the fantastic Rubyize this serie (how humble is that?)
But before we go any further, I’d like to briefly talk about a brand new web 2.0 rails app that has been developed by Marc-André Cournoyer, a Ruby/Rails guru from Montreal. The app is called RefactorMyCode and became instantly popular among the coding community. The principle behind : People submit chunks of their own code that they would wish to see improved. Every members can then try their luck and submit their refactored version of the code. Marc told me that the Rubyize this serie partly inspired him in the creation of this application… it’s always cool to hear things like that!
Ok, now here is what we have to rubyize today :

def remove_insults(input)
   ctr = 0
   input.each do |word|
     word = word.downcase
     if word == "stupid" || word == "moron" || word == "dumbass" || word == "retard"
       i=0
       word.length.times do
          input[ctr][i,1] = "*"
          i+=1
       end
     end
     ctr += 1
   end
   puts input.join(" ").to_s
end
remove_insults "you truly are a moron sir!".split(" ")

Yikes! Pretty ugly this week… that’s how I like them.
IMPORTANT!
Wordpress doesn’t want that you write code… I suggest that you use RefactorMyCode to post your solution instead. You can also use pastie and just write a comment here with the URL to your snippet. The trackbacks are working correctly now so I strongly suggest that you use RefactorMyCode.
If for some reasons you do not wish to use RmC or Pastie, here are some precautions you should take :

  1. Code indentation with spaces doesn’t work. Use another character… an underscore maybe?
  2. Do not use <% or %> (it shouldn’t be a problem this week)
  3. COPY your code in your clipboard before sending it for safety measure… that way if wordpress screw up your code, you will be able to post it again rapidly by just removing what WordPress doesn’t like

Have fun!

25 thoughts on “Rubyize this : 3rd edition

  1. By using RmC right now, it would be like having the same post at 2 different places. But it might not be a bad thing at all after all… let me correct the situation. I just realized that there was Trackback support on RmC

  2. Pingback: RefactorMyCode.com
  3. Hey Frank, thx a lot for the “ad”
    Rubyize this was an inspiration for RefactorMyCode, so it’s an honour to be used for it now!
    Let me know if you got any problem/suggestion w/ the trackback system
    I’ll try to post a refactoring later today 😉

  4. Pingback: RefactorMyCode.com
  5. Pingback: RefactorMyCode.com
  6. Pingback: RefactorMyCode.com
  7. Pingback: RefactorMyCode.com
  8. Pingback: RefactorMyCode.com
  9. Pingback: RefactorMyCode.com

Leave a Reply

Your email address will not be published. Required fields are marked *