history without inheriting Array

master
Kanezoh 2021-08-23 23:44:07 +09:00
parent f0889b8b64
commit 9d797600f9
1 changed files with 9 additions and 6 deletions

View File

@ -1,17 +1,20 @@
require "./page"
class MechanizeCr::History < Array(MechanizeCr::Page)
class MechanizeCr::History
property max_size : Int32
property array : Array(MechanizeCr::Page)
forward_missing_to @array
def initialize(max_size = 100)
@max_size = max_size
super
@array = Array(MechanizeCr::Page).new
end
def push(page, uri = nil)
super page
while self.size > @max_size
shift
@array.push(page)
while size > @max_size
@array.shift
end
self
end
@ -20,6 +23,6 @@ class MechanizeCr::History < Array(MechanizeCr::Page)
if size == 0
# TODO: raise error
end
page = super
page = @array.pop
end
end