lib/tty/prompt/question.rb in tty-prompt-0.22.0 vs lib/tty/prompt/question.rb in tty-prompt-0.23.0

- old
+ new

@@ -53,11 +53,11 @@ @active_color = options.fetch(:active_color) { @prompt.active_color } @help_color = options.fetch(:help_color) { @prompt.help_color } @error_color = options.fetch(:error_color) { :red } @value = options.fetch(:value) { UndefinedSetting } @quiet = options.fetch(:quiet) { @prompt.quiet } - @messages = Utils.deep_copy(options.fetch(:messages) { { } }) + @messages = Utils.deep_copy(options.fetch(:messages) { {} }) @done = false @first_render = true @input = nil @evaluator = Evaluator.new(self) @@ -168,11 +168,11 @@ # Process input # # @api private def read_input(question) - options = {echo: echo} + options = { echo: echo } if value? && @first_render options[:value] = @value @first_render = false end @prompt.read_line(question, **options).chomp @@ -255,10 +255,11 @@ # Set default value. # # @api public def default(value = (not_set = true)) return @default if not_set + @default = value end # Check if default value is set # @@ -275,13 +276,14 @@ # # @api public def required(value = (not_set = true), message = nil) messages[:required?] = message if message return @required if not_set + @required = value end - alias_method :required?, :required + alias required? required # Set validation rule for an argument # # @param [Object] value # @@ -296,10 +298,11 @@ # Prepopulate input with custom content # # @api public def value(val) return @value if val.nil? + @value = val end # Check if custom value is present # @@ -325,22 +328,24 @@ # that the entered characters are not echoed back to the screen. # # @api public def echo(value = nil) return @echo if value.nil? + @echo = value end - alias_method :echo?, :echo + alias echo? echo # Turn raw mode on or off. This enables character-based input. # # @api public def raw(value = nil) return @raw if value.nil? + @raw = value end - alias_method :raw?, :raw + alias raw? raw # Set expected range of values # # @param [String] value # @@ -349,9 +354,10 @@ messages[:range?] = message if message if in? && !@in.is_a?(Range) @in = Converters.convert(:range, @in) end return @in if not_set + @in = Converters.convert(:range, value) end # Check if range is set #