Method: Kernel#prompt

Defined in:
lib/shenanigans/kernel/prompt.rb

#prompt(text = '', conversion = nil) ⇒ Object

Displays a prompt and returns chomped input. Modelled after the Python method raw_input, but also can be supplied with an optional conversion method.

prompt("Prompt> ")
Prompt> 12
#=> "12"

prompt("Prompt> ", :to_f)
Prompt> 12
#=> 12.0


17
18
19
20
21
# File 'lib/shenanigans/kernel/prompt.rb', line 17

def prompt(text='', conversion=nil)
  print text unless text.empty?
  input = gets.chomp
  CONVERSIONS.include?(conversion) ? input.send(conversion) : input
end