This is my attempt at a solution. It's implemented as a module containing two public methods.
ask(prompt, type, options)
ask_if(prompt)
For ask type can either be a symbol (one of :string, :integer, :float or :bool) or it can be a Proc object which is called in order to do the conversion.
options is a hash which can have the following keys,
:validate - this can be either a regular expression or a Proc object
:within - compares the value to the specified range
:above
:below
:default
:base - when converting to an integer this specifies the base of the number. it can be one of b,o,d or x
ask_if is just an alias for ask(prompt, :bool)
highline.rb (3.91 KB)
ยทยทยท
--
Mark Sparshatt