From: matt@... (matt neuburg) Date: 2009-03-31T10:49:55+09:00 Subject: Re: When to use instance variables @ Steve Dogers wrote: > Hi, I have a couple questions about instance variables in Ruby. > 1) do i need to declare them at the top of my class file - I do > understand the accessors are automatic but I'm not sure if I can just > pull a @product in the middle of a function No, nor can you! Code that looks like it is declaring them isn't. A common beginner mistake is illustrated by this experimented: class C @greeting = "howdy" # doesn't do what you might suppose def greet puts @greeting end end C.new.greet #=> nil # surprise! The @greeting that looks like it's being declared in the second line is not, in fact, the instance variable mentioned inside the "greet" method. (It is something else entirely - a "class instance variable".) m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Leopard - http://www.takecontrolbooks.com/leopard-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com