Home > Mobile >  How to check if a specific value exists between values in an array in Ruby
How to check if a specific value exists between values in an array in Ruby

Time:07-13

For example I have an array ['15, Balloons', '1, Onions', '18, Soap']

How do I check if the word "Soap" is in any of the options, ignoring the other value ("18," in this case)?

I've tried using include? but include? only returns boolean if the whole 18, Soap is there

CodePudding user response:

let's check if any of the array's items include Soap

soap_present = arr.any? { |item| item.include?('Soap') }
  •  Tags:  
  • ruby
  • Related