On Wed, 26 Jul 2006, Michael Barinek wrote:

> i'm looking to simplify the below...
>
> @tournament.rounds = Array.new(4) { Round.new }
>
> @tournament.rounds[0].matches =  Array.new(8) { Match.new }
> @tournament.rounds[1].matches =  Array.new(4) { Match.new }
> @tournament.rounds[2].matches =  Array.new(2) { Match.new }
> @tournament.rounds[3].matches =  Array.new(1) { Match.new }
>
> thoughts/suggestions?
>
> -- 
> Posted via http://www.ruby-forum.com/.

this may work for your needs


     harp:~ > cat a.rb
     class Match
       def initialize(idx) @idx = idx end
       def inspect() "#{ self.class } <#{ @idx }>" end
     end

     class Round < ::Array
       def self.new(*a,&b) super(*a){|*_| Match.new *_ } end
     end

     class Tournament < ::Array
     end

     def Match(*a,&b) Match.new(*a,&b); end
     def Round(*a,&b) Round.new(*a,&b); end
     def Tournament(*a,&b) Tournament.new(*a,&b); end

     tournament = Tournament[ Round(8), Round(4), Round(2), Round(1) ]

     p tournament[0]
     p tournament[1]
     p tournament[2]
     p tournament[3]

     p tournament[0][7]
     p tournament[3][0]



     harp:~ > ruby a.rb
     [Match <0>, Match <1>, Match <2>, Match <3>, Match <4>, Match <5>, Match <6>, Match <7>]
     [Match <0>, Match <1>, Match <2>, Match <3>]
     [Match <0>, Match <1>]
     [Match <0>]
     Match <7>
     Match <0>


regards.

-a
-- 
suffering increases your inner strength.  also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama