From 9d797600f9ac3ad51f4e16b33e641d23b9f1da65 Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Mon, 23 Aug 2021 23:44:07 +0900 Subject: [PATCH] history without inheriting Array --- src/mechanize/history.cr | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/mechanize/history.cr b/src/mechanize/history.cr index fed9a40..3588ed0 100644 --- a/src/mechanize/history.cr +++ b/src/mechanize/history.cr @@ -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