history without inheriting Array

This commit is contained in:
Kanezoh 2021-08-23 23:44:07 +09:00
parent f0889b8b64
commit 9d797600f9

View File

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