Ruby: "nomethoderror: undefined method for array" error

Example:

array.non_existent_method
Occurs when you call a method that doesn't exist for that object type.

Solution:

# Use a method that exists for the object or check its existence first.
array.respond_to?(:method_name) && array.method_name

Beginner's Guide to Ruby