module Kernel # Currently only used by prompt: # :to_i, :to_f, :to_r, :to_sym, :to_c CONVERSIONS = [:to_i, :to_f, :to_r, :to_sym, :to_c] # 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 def prompt(text='', conversion=nil) print text unless text.empty? input = gets.chomp CONVERSIONS.include?(conversion) ? input.send(conversion) : input end private :prompt end