Skip to content

Instantly share code, notes, and snippets.

@prepor
Created December 4, 2009 08:53
Show Gist options
  • Save prepor/248915 to your computer and use it in GitHub Desktop.
Save prepor/248915 to your computer and use it in GitHub Desktop.
class FixedStack < Array
attr_accessor :max_size
def initialize(max_size, *args)
self.max_size = max_size
super(*args)
end
def push(*args)
super
self.replace self.last(max_size) if size > max_size
end
alias << push
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment