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

Week 3 pull request - Panda and Tiger Levels #13

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

Week 3 pull request - Panda and Tiger Levels #13

wants to merge 1 commit into from

Conversation

moserrya
Copy link

@moserrya moserrya commented Dec 3, 2012

Spent some time in the Tiger on handling bad inputs. Would love your take on this!

Think I can complete Eagle without fully understanding everything going on, so I am going go spend more time digging in to ActiveRecord first.

Thanks!

count = 0
max_number_of_tries = 2
while days_of_the_week.index(user_date).nil? && count < max_number_of_tries
puts "That is not a valid day of the week. Please try again."
Copy link
Member

Choose a reason for hiding this comment

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

You could probably pull this out into two different methods... maybe something like:

def retry_find_date(times)
  retry_attempts = 0
  begin
    retry_attempts += 1
    return find_date
  rescue InvalidDateError
    if retry_attempts < times
      puts "That is not a valid day of the week. Please try again."
      retry
    else
      puts "No valid date entered, giving shows for today (#{user_date})"
      return days_of_the_week[Time.new.wday]
    end
  end
end

class InvalidDateError < StandardError; end

def find_date
  Date::DAYNAMES.fetch(gets.chomp.capitalize) { raise InvalidDateError.new }
end

Then you'd use it in subjectively cleaner way:

date = retry_find_date(3)
Network.all###

@jwo
Copy link
Member

jwo commented Dec 4, 2012

Most excellent job on this. the comments I left were dealing with organizing code into smaller methods, not with your logic (which was sound). Let me know if you have questions.

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