Working through Day 2 of Ruby in "7 Languages in 7 Weeks" - the answer to the second question seems acceptable, the first one feels quite wrong. Any suggestions?
Print the contents of an array of sixteen numbers, four numbers at a time, using just
each.group = 0 (1..16).each do |x| print x group = group + 1 if group % 4 == 0 puts group = 0 end endNow, do the same with
each_sliceinEnumerable(copied directly from http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-each_slice)(1..16).each_slice(4) {|x| p x}
each, the first solution usesprint and putsfrom the Kernel class, and% and +from Numeric. This book is not for me. – steenslag Feb 28 '12 at 22:55