From: ChrisH Date: 2006-11-16T23:10:08+09:00 Subject: Re: basic mistake? Robert Spielmann wrote: > Hal Fulton schrieb: > > Nia wrote: > >> -------------------------------------------------------- > >> class BookStore > >> @bookstore=Array.new > >> def initialize(*books) > >> i=0 > >> books.each do |x| > >> #@bookstore.push(x) > >> puts "(#{i})" + x.inspect > >> i+=1 > >> end > >> end > >> end ... Hal is correct, moving it into initialize solves the problem. It appears that declaring the instance variable at the class level makes it an instance variable of the class, rather than of the object of the class being created when initialize is called. In short, declare your instance attributes inside initialize. Cheers Chris