Class: QandA::Question::Boolean
- Inherits:
-
QandA::Question
- Object
- QandA::Question
- QandA::Question::Boolean
- Defined in:
- lib/question/boolean.rb
Constant Summary collapse
- TRUES =
['yes', 'y', 'true', 't']
- FALSES =
['no', 'n', 'false', 'f']
Instance Method Summary collapse
- #ask ⇒ Object
-
#initialize(message = '', default = nil) ⇒ Boolean
constructor
A new instance of Boolean.
Constructor Details
#initialize(message = '', default = nil) ⇒ Boolean
Returns a new instance of Boolean.
7 8 9 10 11 12 13 14 |
# File 'lib/question/boolean.rb', line 7 def initialize( = '', default = nil) = "#{message} (y/n)" super(message: , default: default) @validation = Proc.new do |answer| answer = answer.downcase.strip TRUES.include?(answer) || FALSES.include?(answer) end end |
Instance Method Details
#ask ⇒ Object
16 17 18 19 20 21 |
# File 'lib/question/boolean.rb', line 16 def ask super @answer = answer.downcase.strip @answer = true if TRUES.include?(@answer) @answer = false if FALSES.include?(@answer) end |