From feeb2867fb39bcb7f776cb0518cbef9a62a0d1a3 Mon Sep 17 00:00:00 2001 From: Jan Bieron Date: Sat, 28 Feb 2015 23:46:52 +0100 Subject: [PATCH] minor improvements 1.breaks guess loop if no more commits left 2.commits array shuffled only once --- git-game | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/git-game b/git-game index 503eb61..617a4fe 100755 --- a/git-game +++ b/git-game @@ -54,10 +54,16 @@ committers = commits.map { |c| c[:author] }.compact.uniq system('clear') print_header + +if commits.empty? + puts "Couldn't find any commits :(" + exit 0 +end + puts "You're playing in a repo with #{commits.size} commits and #{committers.size}" puts "distinct committers.\n\n" -committers.each do |committer| +committers.sort.each do |committer| puts committer end @@ -67,11 +73,17 @@ gets system('clear') -# -- Game loop -- NUM_CHOICE = 4 +# -- Game loop -- +commit = commits.shuffle! loop do - commit = commits.shuffle.pop + if commits.empty? + puts "Looks like there are no more commits left :(" + break + end + commit = commits.pop + message = commit[:message] author = commit[:author]