Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
  Rafael Herazo
18,114 PointsA little help please
I keep getting the 'address ' variable is not defined
class Address attr_accessor :kind, :street_1, :street_2, :city, :state, :postal_code, :address
def initialize(kind, street_1, street_2, city, state, postal_code, address) @address = address @kind = kind or '' @street_1 = street_1 or '' @street_2 = street_2 or '' @city = city or '' @state = state or '' @postal_code = postal_code or '' end
class Address
  attr_accessor :kind, :street_1, :street_2, :city, :state, :postal_code, :address
  def initialize(kind, street_1, street_2, city, state, postal_code, address)
    @address = address
    @kind = kind or ''
    @street_1 = street_1 or ''
    @street_2 = street_2 or ''
    @city = city or ''
    @state = state  or ''
    @postal_code = postal_code or ''
  end
  def to_s(format = 'short')
    address = ''
    case format
    when 'long'
      address += street_1 + "\n"
      address += street_2 + "\n" if !street_2.nil?
      address += "#{city}, #{state} #{postal_code}"
    when 'short'
      address += "#{kind}: "
      address += street_1
      if street_2
        address += " " + street_2
      end
      address += ", #{city}, #{state}, #{postal_code}"
    end
    address
  end
end
2 Answers
Seth Reece
32,867 PointsHi Rafael,
The challenge is asking "Below the Address class definition, initialize a variable called address which will be a new instance of the Address class."
To do that, outside of the Address class you want to create a variable named address set to equal Address.new(with all required params). e.g.
class Address
  attr_accessor :kind, :street_1, :street_2, :city, :state, :postal_code
  def initialize(kind, street_1, street_2, city, state, postal_code)
    @kind = kind or ''
    @street_1 = street_1 or ''
    @street_2 = street_2 or ''
    @city = city or ''
    @state = state  or ''
    @postal_code = postal_code or ''
  end
  def to_s(format = 'short')
    address = ''
    case format
    when 'long'
      address += street_1 + "\n"
      address += street_2 + "\n" if !street_2.nil?
      address += "#{city}, #{state} #{postal_code}"
    when 'short'
      address += "#{kind}: "
      address += street_1
      if street_2
        address += " " + street_2
      end
      address += ", #{city}, #{state}, #{postal_code}"
    end
    address
  end
end
address = Address.new("Home", "1 some street", "Ste A", "Anytown", "US", "11122")
Rafael Herazo
18,114 PointsThanks a lot, I would have never figured it out.