Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

soap_present = arr.any? { |item| item.include?('Soap') }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading