The include?
method in Ruby only accepts string arguments. When you pass a regular expression to include?
, Ruby raises a
TypeError
with the message "can’t convert regexp to string".
This error occurs at runtime and will cause your application to crash. The include?
method is designed to check if a string contains
another string as a substring, not to perform pattern matching.
For pattern matching with regular expressions, Ruby provides several dedicated methods that are designed for this purpose and handle regex objects
correctly.
What is the potential impact?
This issue causes a runtime TypeError
that will crash the application when the problematic code is executed. This can lead to service
disruption and poor user experience.