[MacRuby-devel] [MacRuby] #250: subclassing Array

MacRuby ruby-noreply at macosforge.org
Fri May 8 19:07:15 PDT 2009


#250: subclassing Array
-------------------------------------+--------------------------------------
 Reporter:  mattaimonetti@…          |       Owner:  lsansonetti@…        
     Type:  defect                   |      Status:  new                  
 Priority:  major                    |   Milestone:                       
Component:  MacRuby                  |    Keywords:  subclassing, Array   
-------------------------------------+--------------------------------------
 {{{
 class Board < Array
   def initialize(*args)
     super
     0.upto(7) do
       self << (0..7).map{[]}
     end
   end
 end

 b = Board.new
 }}}

 {{{
 ./miniruby -I./lib -e "class Board < Array; def initialize(*args); super;
 0.upto(7) do; self << (0..7).map{[]}; end; end; end; p Board.new"
 # => []
 }}}

 {{{
 macruby -e "class Board < Array; def initialize(*args); super; 0.upto(7)
 do; self << (0..7).map{[]}; end; end; end; p Board.new"
 # => []
 }}}


 {{{
 ruby19 -e "class Board < Array; def initialize(*args); super; 0.upto(7)
 do; self << (0..7).map{[]}; end; end; end; p Board.new"
 # => [[[], [], [], [], [], [], [], []], [[], [], [], [], [], [], [], []],
 [[], [], [], [], [], [], [], []], [[], [], [], [], [], [], [], []], [[],
 [], [], [], [], [], [], []], [[], [], [], [], [], [], [], []], [[], [],
 [], [], [], [], [], []]]
 }}}

 {{{
 ruby -e "class Board < Array; def initialize(*args); super; 0.upto(7) do;
 self << (0..7).map{[]}; end; end; end; p Board.new"
 # => [[[], [], [], [], [], [], [], []], [[], [], [], [], [], [], [], []],
 [[], [], [], [], [], [], [], []], [[], [], [], [], [], [], [], []], [[],
 [], [], [], [], [], [], []], [[], [], [], [], [], [], [], []], [[], [],
 [], [], [], [], [], []]]
 }}}

 I think the problem is pretty obvious, let me know if you need more
 explanations.

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/250>
MacRuby <http://macruby.org/>



More information about the MacRuby-devel mailing list