You can use the String
class's =~
method with the regex /d/
as the argument.
Here's an example:
s = 'abc123'
if s =~ /d/ # Calling String's =~ method.
puts "The String #{s} has a number in it."
else
puts "The String #{s} does not have a number in it."
end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…