Ruby Build an Address Book in Ruby Class Design Initializing and Calling Methods

Ray Edison Refundo
Ray Edison Refundo
3,798 Points

Initialize a variable called address which will be a new instance of the Address class?

I am totally stumped on this question If someone knows the answer and can explain I would be very appreciative.

address.rb
class Address
  attr_accessor :kind, :street_1, :street_2, :city, :state, :postal_code

  address = Address.new

  def address(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

2 Answers

Sage Elliott
Sage Elliott
30,002 Points

Hey ray! Sometimes it can be confusing when reading the question, but what it's asking for is creating a new variable called "address" and passing in a argument to create a new address!

Try something like this

#Code that's already in challenge.
address = Address.new('My_Home', '123 home St.', 'home Rd.', 'Seattle', 'WA', '12345')

Make sure you understand whats happening there and don't just copy/paste and move on :)

Ray Edison Refundo
Ray Edison Refundo
3,798 Points

Ah, fixed up my answer. Thanks a lot! I got a really confused by the wording of the question. I didn't realize I had to add a complete address.

Sage Elliott
Sage Elliott
30,002 Points

It happens to me all the time!