require 'stack_contract' class Stack contract StackContract class NoPopForEmptyStack < RuntimeError end def initialize @elements = [] end def initialize_copy(orig) @elements = orig.elements end def elements @elements.dup end def size @elements.size end def empty? size == 0 end def top @elements.last end def push(element) @elements.push(element) nil end def pop raise NoPopForEmptyStack if empty? @elements.pop end end