The below function will throw a NoMethodError when it is expected to calculate the sum of a given array.
By printing the result "p" it should return 10.
p [1,2,3,4].sum
#=> 10
Instead of getting the result of the sum, I get the error below.
undefined method `sum' for [1, 2, 3, 4]:Array (NoMethodError)
sum
was added in Ruby 2.4, you're probably running an older version. – Oldenburg