On Oct 19, 4:35 pm, Li Chen <chen_... / yahoo.com> wrote:
> Hi folks,
>
> I have an array containing 96 elements. I want to print the array in
> 12x8 format. Any comments?
>
> Thanks in advance,
>
> Li
>

Hi.

The slicing method is neat.
However, not having the book, this is what i came upon, supposing you'd
want to keep the string and not only to print it.

class Array
  def print_format(width)
    str = ''
    from_index = 0
    while !self[from_index].nil?
      str << self[from_index, width].inspect + "\n"
      from_index += width
    end
    str
  end
end

n = (1..96).to_a
puts n.print_format(8)

Conclusion: I want my book!
Regards.