What does Array.any mean? (&: Nil?)?

I am new to ruby ​​and working on a tutorial but not sure what this line of code means:

[movie, version_number].any?(&:nil?)

From my research, Array.any?returns true if any of the elements in the array is not falseor nil. And &:nil?means a call to_proc()to the :nil?ie symbol :nil?.to_proc, therefore the operator is equivalent

[movie, version_number].any?(:nil?.to_proc)

which is equivalent

[movie, version_number].any?{|item| item.nil?}

Next, any?Skips each item in the collection (in this case, Array) into a block {|item| item.nil?}.

When you add them together, does a line of code mean, call nil?for each element of the array before calling .any?in the array, i.e. it is equivalent:

[movie.nil?, version_number.nil?].any?

Or, in plain English, is there any movie or version_number equal to nil?

+4
1

# to_proc:

Proc, sym.

(1..3).collect(&:to_s)  #=> ["1", "2", "3"] 

, , :

[movie, version_number].any?{|item| item.nil? }

any? , [1] , true, true .

to_proc Symbol - , , . , , .

[1] , procs lambdas ruby ​​

+5

Source: https://habr.com/ru/post/1693480/


All Articles