To check if a string contains a specific character in Ruby, you can use the 'include?' method.
In this example,
def contains_character(str, ch)
str.include?(ch)
end
str = "Hello World"
ch = 'W'
contains = contains_character(str, ch)
puts "String contains character '#{ch}': #{contains}"
String contains character 'W': true
In this tutorial, we learned How to Check if String contains specific Character in Ruby language with well detailed examples.