On Sat, Aug 28, 2010 at 11:17 AM, Cameron Vessey <cameron1inm / hotmail.com>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}"