Class: Clin::ShellInteraction::YesOrNo

Inherits:
Clin::ShellInteraction show all
Defined in:
lib/clin/shell_interaction/yes_or_no.rb

Overview

Handle a simple yes/no interaction

Instance Attribute Summary

Attributes inherited from Clin::ShellInteraction

#shell

Instance Method Summary collapse

Methods inherited from Clin::ShellInteraction

#initialize, #persist!, #persist?, #persist_answer

Constructor Details

This class inherits a constructor from Clin::ShellInteraction

Instance Method Details

#run(statement, default: nil, persist: false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/clin/shell_interaction/yes_or_no.rb', line 5

def run(statement, default: nil, persist: false)
  default = default.to_sym unless default.nil?
  options = [:yes, :no]
  if persist
    return true if persist?
    options << :always
  end
  choice = @shell.choose(statement, options, default: default, allow_initials: true)
  return persist! if choice == :always
  choice == :yes
end