I have this class that needs to do three things:
- Determine if a string is 8 characters or longer
- Determine if a string has a number in it
- Determine if a string has a capital letter in it
NB: I don't want to use regex. Is there a better way of doing this?
class ValidateString
def initialize(string)
@string = string
if valid
puts @string
end
end
def valid
if has_number? and has_upper? and has_length?
return @string
end
end
def has_number?
@string.count("0-9") > 0
end
def has_upper?
@string =~ /[A-Z]/
end
def has_length?
@string.length >= 8
end
end
has_upper?
by the way) \$\endgroup\$