Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby non_empty? method

I want to use expression:

!([1,2,3] & [43,5]).empty?
=> false
!([1,2,3] & [3,5]).empty?
=> true

to check if two arrays contains at least one common value. And I wonder if there is a better way of doing it? Maybe something like:

 ([1,2,3] & [3,5]).non_empty?

How to write non_empty? method?

like image 572
klew Avatar asked Mar 22 '26 04:03

klew


1 Answers

([1,2,3] & [3,5]).any?
like image 73
JHurrah Avatar answered Mar 25 '26 01:03

JHurrah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!