Skip to content

Commit fe8018b

Browse files
author
Devan Hurst
committed
Convert conditional from a guard clause to an if/else.
1 parent bd4e62b commit fe8018b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/thor/shell/basic.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,11 @@ def ask_filtered(statement, color, options)
463463
end
464464

465465
def answer_match(possibilities, answer, case_insensitive)
466-
return possibilities.detect{ |possibility| possibility == answer } unless case_insensitive
467-
possibilities.detect{ |possibility| possibility.downcase == answer.downcase }
466+
if case_insensitive
467+
possibilities.detect{ |possibility| possibility.downcase == answer.downcase }
468+
else
469+
possibilities.detect{ |possibility| possibility == answer }
470+
end
468471
end
469472

470473
def merge(destination, content) #:nodoc:

spec/shell/basic_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def shell
8181
expect(shell.ask('What\'s your favorite Neopolitan flavor?', :limited_to => flavors)).to eq("chocolate")
8282
end
8383

84-
#this one
8584
it "prints a message to the user with the available options, expects case-sensitive matching, and reasks the question after a case-insensitive match" do
8685
flavors = %w(strawberry chocolate vanilla)
8786
expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n")

0 commit comments

Comments
 (0)