From: Hal Fulton Date: 2006-11-16T14:21:21+09:00 Subject: Re: basic mistake? 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 > > class Book > def initialize(name,cost) > @book_name=name > @book_cost=cost > end > > def detail > puts "Book: #{@book_name} ($#{@book_cost})" > end > end > > b1=Book.new('Harry Potter','9.95') > b2=Book.new('The Raven','8.65') > store = BookStore.new(b1,b2) > -------------------------------------------------------------- > this bit of code seems to work fine, but when i try to assign an object to my bookstore > array, i'm given an error(i commented it out since it wasn't working). wierd part is that this > seem to work fine outside of a class. am i missing something?, like a declaration? this isn't > the first time i've encounter this problem. please help me solve it. > At least two mistakes here... move the @bookstore line down into the initialize method. And take off the # from that line -- that makes it a comment. Hal