Given the following code:
class Person
attr_accessor :first_name, :last_name
@@people = []
def initialize(first_name,last_name)
@first_name = first_name
@last_name = last_name
@@people.push(self)
end
def self.search(last_name)
@last_name = last_name #accept a `last_name` parameter
@@people.select { |person| person.last_name }
#return a collection of matching instances
end
#have a `to_s` method to return a formatted string of the person's name
def to_s
#return a formatted string as `first_name(space)last_name`
end
end
p1 = Person.new("John", "Smith")
p2 = Person.new("John", "Doe")
p3 = Person.new("Jane", "Smith")
p4 = Person.new("Cool", "Dude")
puts Person.search("Smith")
# Should print out
# => John Smith
# => Jane Smith
What do I need to do to return the output under the Should print out bit? I can get it to return the object id:
#<Person:0x007fa40c04cd08>
#<Person:0x007fa40c04c920>
#<Person:0x007fa40c04c5d8>
#<Person:0x007fa40c04c5b0>
One problem that I see with that without even knowing what is in each one: there should only be two values returned. So clearly the search portion is also wrong.
What should I be doing with this?
Person#to_sto do what the comment says - "# return a formatted string as first_name(space)last_name" - then iterate over whatPerson#searchreturns and callPerson#to_son each object.