Copyright (c) 2012 Alex Suraci
Ask a question and get an answer. Rewind-aware; call disable_rewind on your class to disable.
See Interact#ask for the other possible values in options.
The prompt, without ": " at the end.
An optional hash containing the following options.
forget |
Set to true to prevent rewinding from remembering the user's answer. |
# File lib/interact/rewindable.rb, line 39 def ask(question, options = {}) rewind = HAS_CALLCC if rewind prompt, answer = callcc { |cc| [cc, nil] } else prompt, answer = nil, nil end if answer options[:default] = answer end prompts = (@__prompts ||= []) options[:prompts] = prompts ans = super if rewind prompts << [prompt, options[:forget] ? nil : ans] end ans end
Clear prompts.
Questions asked after this are rewindable, but questions asked beforehand are no longer reachable.
Use this after you've performed some mutation based on the user's input.
# File lib/interact/rewindable.rb, line 71 def finalize @__prompts = [] end
Generated with the Darkfish Rdoc Generator 2.