On Oct 11, 2005, at 3:46 PM, James Edward Gray II wrote:

>> #!/usr/bin/ruby
>>
>> # Add the ability to more than one object
>> # out of a collection
>> class Array
>>   def pick(num)
>>      (0...self.length).step(num) do
>>        |i| yield self[i...i+num]
>>      end
>>   end
>> end
>>
>
> Clever, I like that.
>
>
>> # Print Tic Tac Toe board
>> def print_board(b)
>>   puts "+---+---+---+"
>>   b.pick(3) do |x,y,z|
>>     puts "| #{x} | #{y} | #{z} |"
>>     puts "+---+---+---+"
>>   end
>> end
>>
>
> Looks good here.

An alternative:

require "enumerator"

def print_board( b )
   puts "+---+---+---+"
   b.each_slice(3) do |row|
     puts "| #{row.join(' | ')} |"
     puts "+---+---+---+"
   end
end

See tomorrow's Ruby Quiz summary for a detailed explanation... ;)

James Edward Gray II