shift会从元素的开端移除一个对象(因此,剩余的对象像左移动 一个位置),pop会移除数组末端的一个元素。shift和pop都会返回它们移除数组的元素。
a=[1,2,3,4,5]
print "the original array"
p a
popped=a.pop
print "the popped item"
p poped
print "the new state of the array"
p a
shifted=a.shift
print "the shifted item"
puts shifted
print "the new state of the array"
p a
输出结果
the original array :[1,2,3,4,5]
the popped item:5
the new state of the array:[1,2,3,4]
the shifted item 1
the new state of the array [2,3,4]