@@ -31,29 +31,45 @@ def concat(*val)
31
31
def push ( *val )
32
32
# If history_size is zero, all histories are dropped.
33
33
return self if @config . history_size . zero?
34
- diff = size + val . size - @config . history_size
35
- if diff > 0
36
- if diff <= size
37
- shift ( diff )
38
- else
39
- diff -= size
40
- clear
41
- val . shift ( diff )
34
+ # If history_size is negative, history size is unlimited.
35
+ if @config . history_size . positive?
36
+ diff = size + val . size - @config . history_size
37
+ if diff > 0
38
+ if diff <= size
39
+ shift ( diff )
40
+ else
41
+ diff -= size
42
+ clear
43
+ val . shift ( diff )
44
+ end
42
45
end
43
46
end
44
- super ( *( val . map { |v | String . new ( v , encoding : Reline . encoding_system_needs ) } ) )
47
+ super ( *( val . map { |v |
48
+ String . new ( v , encoding : Reline . encoding_system_needs )
49
+ } ) )
45
50
end
46
51
47
52
def <<( val )
48
53
# If history_size is zero, all histories are dropped.
49
54
return self if @config . history_size . zero?
50
- shift if size + 1 > @config . history_size
55
+ # If history_size is negative, history size is unlimited.
56
+ if @config . history_size . positive?
57
+ shift if size + 1 > @config . history_size
58
+ end
51
59
super ( String . new ( val , encoding : Reline . encoding_system_needs ) )
52
60
end
53
61
54
62
private def check_index ( index )
55
63
index += size if index < 0
56
- raise RangeError . new ( "index=<#{ index } >" ) if index < -@config . history_size or @config . history_size < index
64
+ if index < -2147483648 or 2147483647 < index
65
+ raise RangeError . new ( "integer #{ index } too big to convert to `int'" )
66
+ end
67
+ # If history_size is negative, history size is unlimited.
68
+ if @config . history_size . positive?
69
+ if index < -@config . history_size or @config . history_size < index
70
+ raise RangeError . new ( "index=<#{ index } >" )
71
+ end
72
+ end
57
73
raise IndexError . new ( "index=<#{ index } >" ) if index < 0 or size <= index
58
74
index
59
75
end
0 commit comments