on master help sign in
More idiomatic code for the ruby fold benchmark
commit06a5572eb8b6ec85f564dbae69563cfbed982b50 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateThu 16 Jun 2011, 15:23 (15 years ago) parent8de5ea9
1 file changed+4−4
tests/benchmarks/ruby/fold.rb+4−4
tests/benchmarks/ruby/fold.rb+4−4
@@ -10,7 +10,7 @@ def fold(filename, max_width)
1010 file.each_line do |line|
1111 # If we encounter an empty line, we reformat and dump the current
1212 # paragraph
13− if line.strip.empty? then
13+ if line.strip.empty?
1414 puts fold_paragraph(paragraph, max_width)
1515 puts
1616 paragraph = []
@@ -32,11 +32,11 @@ def fold_paragraph(paragraph, max_width)
3232 width = str.length
3333
3434 paragraph.drop(1).each do |word|
35− if width + word.length + 1 <= max_width then
36− str += ' ' + word
35+ if width + word.length + 1 <= max_width
36+ str << ' ' + word
3737 width += word.length + 1
3838 else
39− str += "\n" + word
39+ str << "\n" + word
4040 width = word.length
4141 end
4242 end