I have an array (@tasks) from a database select and I want to display the first on its own and then loop through any others.
There will always be one item in the array but there may or may not be more than one.
What’s the best way to show the first one and then loop through any remaining items, if there are any more?
I thought I found something similar on SO the other day but I can’t seem to find it again.
Thanks
However, in the above case, if
a = [1]thenthe_restwill end up beingnil(at least in ruby 1.9, dunno about 1.8)You could also use
.shiftto remove the first element like so: