Refactoring For Loop so it's on only 1 line?


After completing the Ruby Zen chapter I revisted this and am wondering if there is a way to refactor a for loop so that it's on one line? I've tried...

for num in 1...10 { puts num }

but it doesn't seem to work.

Replace this line with your code.


Think I figured it out. If anyone knows, please confirm if this is the best way.

for num in 15..20 do print "#{num}, " end


Here's something to play around with:

(15..20).each { |x| puts "#{x}" }