From: Ziheng Lin Date: 2010-01-24T01:32:16+09:00 Subject: Re: how to define []= Colin Bartlett wrote: > On Sat, Jan 23, 2010 at 2:29 PM, hagbard > wrote: >>> But how do we define the set method `[]='? >> >> Just define it. >> def []=(i, value) >> � @ary[i] = value >> end > > And for a two dimensional array: > class QQ > def initialize( arr ) ; @ary = arr ; end > def []( i, j ) ; @ary[i][j] ; end > def []=( i, j, value ) ; @ary[i][j] = value ; end > end I dint know it also works for multi-dimension arrays.. Thanks! -- Posted via http://www.ruby-forum.com/.