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

janeporter
PRO
janeporter
Pro Student 23,471 Points

code getting an ArgumentError: wrong number of arguments (0 of 6)...but i have the arguments...

here is my code:

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 address(kind, street_1, street_2, city, state, postal_code) address.kind = kind address.street_1 = street_1 address.street_2 = street_2 address.city = city address.state = state address.postal_code = postal_code 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 address.address("Home", "123 Main St.", "", "Dallas", "TX", "75243")

which is not passing the challang and i don't know why, looks like i have the correct number of arguments to me...

2 Answers

William Li
PRO
William Li
Pro Student 26,794 Points

Yes indeed, the required arguments are there; however, you need to initialize a new instance of Class and pass in required arguments to it, all in ONE line.

address = Address.new("Home", "123 Main St.", "", "Dallas", "TX", "75243")

Like such, hope it helps.

janeporter
PRO
janeporter
Pro Student 23,471 Points

Hello William. That worked. Thank you.