Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiger Level #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Tiger Level #19

wants to merge 1 commit into from

Conversation

habutai
Copy link

@habutai habutai commented Mar 27, 2013

I probably left in more output than I need to.

It also double-asks on search again after a valid search with a N answer for some reason. I can't figure out why.

I might touch on the Panda Level at some point, but right now, the ActiveRecord::Base API docs are just making me want to flip out.

@@ -4,6 +4,6 @@ class Show < ActiveRecord::Base
validates_presence_of :name

def to_s
"#{name} airs at #{hour_of_day}:#{day_of_week}:00 on #{network} "
"#{id.inspect}: #{name} airs at #{day_of_week}:#{hour_of_day}:00 on #{network} "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you use the "inspect" method on id ---- each object has both a to_s and an inspect method, but for different uses. Inspect should only be used for IRB style introspection. Basically looking at an object. Here you could just do:

"#{id}: #{name} airs at #{day_of_week}:#{hour_of_day}:00 on #{network} "

@jwo
Copy link
Member

jwo commented Mar 27, 2013

Nice job!

OK, so the deal with the asking you more than twice is a problem with recursion. In your example:

  1. We call find_shows
  2. that calls search_again
  3. the search_again calls find_shows
  4. so there are now two "instances" of the find_shows method.

I reworked a tiny bit. See if this makes sense to you:

def search_again
  puts "Search Again (Y/N)" 
  answer = gets.upcase[0]
  answer == "Y"
end


def find_show

  keep_searching = true
  while keep_searching do
    puts "What day do you want to watch TV? (ex: Sunday)"
    day = gets.chomp

    shows = Show.find(:all, :conditions => {:day_of_week => day})
    if shows.any?
      shows.each do |show|
        puts show
      end
      keep_searching = search_again
    else
      puts "There was nothing found for #{day}"
    end
  end
end

The important part above is setting the keep_searching = search_again --- that way, we only have 1 loop to care about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants