From: Robert Klemme Date: 2009-09-16T17:19:27+09:00 Subject: Re: Making an array wrap, where last index + 1 = first index 2009/9/15 Aldric Giacomoni : > def class Array2D < Array >  def []( index ) >    super [] index % self.length >  end > end > > How about that? 10:16:29 c$ ruby -c < def class Array2D < Array > def []( index ) > super [] index % self.length > end > end > EOF -:1: formal argument cannot be a constant def class Array2D < Array ^ -:1: syntax error, unexpected '<', expecting '\n' or ';' def class Array2D < Array ^ -:3: syntax error, unexpected tIDENTIFIER, expecting kEND super [] index % self.length ^ -:5: syntax error, unexpected kEND, expecting $end 10:16:35 c$ Rather 10:18:27 c$ ruby19 < class ArrayWrap < Array > def []( index ) > super(index % length) > end > end > a = ArrayWrap.new(5) {|i| i} > 7.times do |i| > printf "%2d %2d\n", i, a[i] > end > EOF 0 0 1 1 2 2 3 3 4 4 5 0 6 1 10:19:08 c$ Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/