Method: HighLine#agree
- Defined in:
- lib/highline.rb
#agree(yes_or_no_question, character = nil) ⇒ Object
A shortcut to HighLine.ask() a question that only accepts “yes” or “no” answers (“y” and “n” are allowed) and returns true
or false
(true
for “yes”). If provided a true
value, character will cause HighLine to fetch a single character response. A block can be provided to further configure the question as in HighLine.ask()
Raises EOFError if input is exhausted.
200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/highline.rb', line 200 def agree(yes_or_no_question, character = nil) ask(yes_or_no_question, ->(yn) { yn.downcase[0] == "y" }) do |q| q.validate = /\A(?:y(?:es)?|no?)\Z/i q.responses[:not_valid] = 'Please enter "yes" or "no".' q.responses[:ask_on_error] = :question q.character = character q.completion = %w[yes no] yield q if block_given? end end |