Kirill Zhuravlov Kirill Zhuravlov - 4 months ago 26
Ruby Question

Ruby: How to check that all elements in array are negative integers

I have the arrays

a = [-1,-2,-3,-4]
b = [-1,-2,-3,4]

How can I make sure that
contains only negative integers?
I can check that some of elements are negative == true
and == true

But I need to know that == true


You can use Enumerable#all? here:

#=> true

Btw, I think you are confused with what is happening here: == true

This is not checking whether all elements are negative. What it is in fact is comparing resulting array of negative numbers with false:

[-1,-2,-3,-4] == false

Of course, it will always return false, because only false is equal to false.