Ruby Build an Address Book in Ruby Input and Output Displaying a Menu

Loi Tran
Loi Tran
9,053 Points

print_results a part of the public domain?

Hey guys, does anyone here know if 'print_results' is in the public domain? I don't know why this isn't executing. code. https://gist.github.com/Lvtran1987/d6322db131c037045184 The only credible source I found/am familiar with says yes, however the github link it gives us is no longer a working page, so I'm pretty sure the page has been removed, unless github now blows and cant program well? Haha. Rubydoc page http://www.rubydoc.info/github/opscode/chef/Chef%2FKnife%2FList%3Aprint_results missing page https://github.com/chef/chef/blob/Chef%2FKnife%2FList%3Aprint_results/lib/chef/knife/list.rb#L123

3 Answers

Ah ha! Sorry, I was just looking at the top-level forum while drinking my morning coffee.

If Jason uses it, it's almost certainly got to be a method he's already written somewhere. I took a quick peek at the course, and it looks like the print_results method is included in the Teacher's Notes section of the Searching by Phone Number video:

def print_results(search, results)
  puts search
  results.each do |contact|
    puts contact.to_s('full_name')
    contact.print_phone_numbers
    contact.print_addresses
    puts "\n"
  end
end
Loi Tran
Loi Tran
9,053 Points

Hm. I seem to have written my code differently for the find_by_phone. This yielded me the results I wanted. Haha. I often work ahead in order to figure out whether or not I'm actually any good at this (My way of evaluating myself)

That being said, heres my link. https://gist.github.com/Lvtran1987/1f3447ad6137ac8ea360 When you suggested that I look at the find_by_phone method and I saw different code than his then I just decided to copy and paste mine over... and now the find_by_address method works =). Thanks~!

Hi! You've linked to some documentation for a method that's part of third-party program called Chef, which is written in Ruby but not actually part of Ruby itself.

Unless you've specifically added a third-party program in your code, you'll want to stick to using methods that are either part of Ruby itself or ones you've written as part of your program. Documentation for the core Ruby methods is here: http://ruby-doc.org/

In your case, you probably want to use the 'puts' or 'print' methods to output to the screen. You might also want to use a loop of some kind to go through each element of the results array, outputting each in turn.

Loi Tran
Loi Tran
9,053 Points

Greg, I understand everything you said. And I have tried to do the puts and print method. However the print_result is part of a query. This is the address book exercise we do in Ruby. If it isn't a part of the public domain why does Jason use it..? He uses it in the exercise when we're trying to add the method to our address_book which allows us to find_by_address.

Thanks for taking the time to respond!