have an array that contains objects from different classes, not all just one type. : Array Elements « Array « Ruby






have an array that contains objects from different classes, not all just one type.


# here's an array that contains four elements, each a different kind of object

hodge_podge = ["January", 1, :year, [2006,01,01]]

# Use each to iterate over the array, and class to find what kind of object each element is:

hodge_podge.each {|e| print e.class, " " } # => String Fixnum Symbol Array

 








Related examples in the same category

1.Accessing Elements
2.use the at method
3.Access the last element in the array
4.With -1, you access the last element in an array by looping back around with a negative number.
5.To change three of the elements to have German rather than English spelling.
6.With start and length parameters
7.Replacing subarrays with []=
8.Change character case of an element