Skip to content

Tiger Level - #19

Open
habutai wants to merge 1 commit into
RubyoffRails:masterfrom
habutai:master
Open

Tiger Level#19
habutai wants to merge 1 commit into
RubyoffRails:masterfrom
habutai:master

Conversation

@habutai

Copy link
Copy Markdown

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.

Comment threadmodels/show.rb

Copy link
Copy Markdown
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

jwo commented Mar 27, 2013

Copy link
Copy Markdown
Member

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:

defsearch_againputs"Search Again (Y/N)"answer=gets.upcase[0]answer == "Y"enddeffind_showkeep_searching=truewhilekeep_searchingdoputs"What day do you want to watch TV? (ex: Sunday)"day=gets.chompshows=Show.find(:all,:conditions=>{:day_of_week=>day})ifshows.any?shows.eachdo |show|
putsshowendkeep_searching=search_againelseputs"There was nothing found for #{day}"endendend

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

Sign up for freeto 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

@habutai@jwo