Sha256: 05271e217273fc81551dc3ffd54d09fcc725fb33665c4370e0d9b7c4c9e424d2
Contents?: true
Size: 696 Bytes
Versions: 1
Compression:
Stored size: 696 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) #:doc: print text unless text.empty? input = gets.chomp CONVERSIONS.include?(conversion) ? input.send(conversion) : input end private :prompt end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shenanigans-1.0.13 | lib/shenanigans/kernel/prompt.rb |