def randomize_case(string)
letters = string.split("")
new_string = ""
letters.each do |letter|
new_string += (rand(2)) == 0 ? letter.downcase : letter.upcase
end
new_string
end
Refactorings
No refactoring yet !
michal-pochwala.myopenid.com
August 22, 2011, August 22, 2011 08:06, permalink
I am beginning with ruby so your comments are welcome.
#my try [ruby]
def randomize_case(string)
string.each_char.inject(""){ |result,char| result+ ((rand(2)) == 0 ? char.downcase : char.upcase) }
end
Is there a better, shorter and most importantly more beautiful way of doing the same thing?