From: Josh Cheek Date: 2010-08-29T17:11:55+09:00 Subject: Re: initialize instance variable problem --001485f2d0d6789654048ef1e6a3 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Aug 28, 2010 at 11:17 AM, Cameron Vessey wrote: > Why does this return nil for @city? > > class Url > def initialize(city,quary,catagory,minask,maxask) > @city = city > @quary = quary > @cat = catagory > @min = minask > @max = maxask > end > > puts @city > > end > a = Url.new('spokane',"tires","pts","0","1000") > a > -- > Posted via http://www.ruby-forum.com/. > > This is basically what Jean said, but I figured it might be easier to follow if you can actually see it. class Url # self is the class Url puts "outside initialize 1, self is #{self.inspect}" def initialize(city,quary,catagory,minask,maxask) @city = city @quary = quary @cat = catagory @min = minask @max = maxask # self is an instance of Url puts "Inside initialize 3, self is #{self.inspect}" end # self is the class Url puts "outside initialize 2, self is #{self.inspect}" def render # self is an instance of Url puts "Inside initialize 4, self is #{self.inspect}" @city + @quary + @cat + @min + @max end end a = Url.new('spokane',"tires","pts","0","1000") result = a.render puts "result is #{result.inspect}" --001485f2d0d6789654048ef1e6a3--