On Monday 25 August 2008, Amanda … wrote:
hi there, I’m trying to add objects onto the end of an array and I’m
getting a NoMethodError with the message “undefined method `push’ for
Array:Class”. This makes no sense to me as “push” should be defined for
Any help would be great, thanks!
It seems your code is something like
This doesn’t work because push is an instance method of the Array class,
is: you need to call it on an individual array (an instance of class
not on the Array class itself. This is how you should do it:
a = Array.new
(the syntax [1,2,3] creates an array, instance of class Array,
items 1, 2 and 3).
I hope this helps