Ruby string contains Code Example

Last Updated On Thursday 20th Jan 2022

include? – Returns true if a string is in another string.

Check if a string includes a specified character(s), case sensitive.

	'hello World'.include? hello.'

The Above Code returns

  • include? method is case sensetive.
  • You may want to do a downcase() or upcase() before calling include?()
  • str.upcase => Returns entire str lower cased. upcase! mutates.
  • str.downcase => Returns entire str upper cased. downcase! mutates.
	if "abcd".include? "bc"
   puts "It includes 'bc'"

The Above Code returns

	It includes 'bc.'