Sha256: ed6dfc5e03ad500fd24d94a11193b2d4a9ea2c961f6a54db8fc8f784ca55301e
Contents?: true
Size: 671 Bytes
Versions: 9
Compression:
Stored size: 671 Bytes
Contents
module Kernel # Currently only used by <tt>prompt</tt>: # <tt>:to_i</tt>, <tt>:to_f</tt>, <tt>:to_r</tt>, <tt>:to_sym</tt>, <tt>:to_c</tt> CONVERSIONS = [:to_i, :to_f, :to_r, :to_sym, :to_c] # Displays a prompt and returns chomped input. # Modelled after the Python method <tt>raw_input</tt>, 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 end
Version data entries
9 entries across 9 versions & 1 rubygems