diff options
Diffstat (limited to 'lib/highline/question.rb')
-rw-r--r-- | lib/highline/question.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/highline/question.rb b/lib/highline/question.rb index ce2245d..8fcd68d 100644 --- a/lib/highline/question.rb +++ b/lib/highline/question.rb @@ -145,6 +145,9 @@ class HighLine # If set to a Regexp, the answer must match (before type conversion). # Can also be set to a Proc which will be called with the provided # answer to validate with a +true+ or +false+ return. + # It's possible to use a custom validator class. It must respond to + # `#valid?`. The result of `#inspect` will be used in error messages. + # See README.md for details. # attr_accessor :validate # Used to control range checks for answer. @@ -502,7 +505,8 @@ class HighLine def valid_answer? !validate || (validate.is_a?(Regexp) && answer =~ validate) || - (validate.is_a?(Proc) && validate[answer]) + (validate.is_a?(Proc) && validate[answer]) || + (validate.respond_to?(:valid?) && validate.valid?(answer)) end # |