LIFO inplementation in ruby