From: jake kaiden Date: 2011-09-04T10:01:14+09:00 Subject: Re: arrays(setters and getters) hi Shehio, so, a couple of things... > # whats wrong with that > class Whatever > attr_accessor :array > @array ### THIS IS NOT NECESSARY > def initialize > @array = [] ### THIS IS NOT NECESSARY EITHER > @array = ["apple", "banana", "peach"] > end ### THE FOLLOWING IS NOT NECESSARY > def array []= (i,value) # setter > @array[i] = value > end > def array[] (i) #getter > @array[i] > end > end this code could read: class Whatever attr_accessor :array def initialize @array = ["apple", "banana", "peach"] end end and all of this will work just fine: shehio = Whatever.new puts shehio.inspect puts shehio.array puts shehio.array[0] puts shehio.array[1] puts shehio.array[2] shehio.array[0] = 1 shehio.array[0] = 2 shehio.array[0] = 3 puts shehio.array[0] puts shehio.array[1] puts shehio.array[2] - j -- Posted via http://www.ruby-forum.com/.