Saturday, 8 February 2014
Reversing The Elements In A Ruby Array
my_array = ['mark','dave',1,2,3,'x']
Next we will use the reverse command on this array like so:
This will print the following output to your screen.
Notice here that this output has been printed out like a list. The reason for this is that we used 'puts' to output it. If you want to see the output of your array printed on the same line, simply substitute the 'puts' command for the Ruby 'print' command like so.
["x", 3, 2, 1, "dave", "mark"]
And hey voila Ruby will print the output on the same line!