1000.times better
Short code post. Just the story of how do you get someone looking into Ruby when they had already dismissed it as a fad. You know, the hype can blind you.
So the situation arrived when a friend needed to have a particular chunk of XML repeated 1000 times. No more, no less. Sounds stupid but it's just an oversimplified anecdote.
When he asked me for a quick script to do it for him, I saw an opportunity to show how Ruby would be a good tool for this job (insert promo here). Being a "show, don't tell" kind of guy, this was the code I presented him.
def thousand_repeater(string, repeats =1000)
repeats.times do
print "#{string}\n"
end
end
Not too fancy by any means. You just have to call it with the string you want, optionally provide the number of times you want it repeated and that's pretty much it.
Ex.: thousand_repeater "hello",3
The thing that got to him was actually the ability that Ruby gives you of doing something like "1000.times", compared to the more familiar (at least for him)
for(i=1; i<1000; i++)
Thats it.