To fix the syntax error in your Ruby code, you need to remove the colon before the &
operator in the all?
method. Here is the corrected code:
main.rb30 chars2 lines
In this code, &:even?
is a shorthand notation for passing the even?
method as a block to the all?
method. It will return true
if all elements in the array are even, and false
otherwise.
Make sure to run the code in a Ruby environment to see the correct output.
gistlibby LogSnag