Well it doesn't work for "de " either
2.3.0 :004 > "van test".include?("van " || "de " || "von ")
=> true
2.3.0 :005 > "de test".include?("van " || "de " || "von ")
=> false
2.3.0 :006 > "von test".include?("van " || "de " || "von ")
=> false
When you run String#include?("van " || "de " || "von ")
you pass only one argument to the function: "van " || "de " || "von "
.
Boolean OR (||
) will return the first element of the list that evaluates to true. So this is strictly identical to String#include?("van ")
.
I know only two ways to do what you were trying to do in just one line :
You can make a table of substrings to test and use any?
over it
["van ", "de ", "von "].any? { |s| string.include?(s) }
Or you can use a regex (in which the or operator (|
) does exactly what you want)
/van |de |von / =~ string