| Class | IRB::History |
| In: |
lib/irb/ext/history.rb
|
| Parent: | Object |
| inspect | -> | real_inspect |
# File lib/irb/ext/history.rb, line 54
54: def initialize(size = 16)
55: @size = size
56: @contents = []
57: end
# File lib/irb/ext/history.rb, line 66
66: def [](idx)
67: begin
68: if idx >= 0
69: @contents.find{|no, val| no == idx}[1]
70: else
71: @contents[idx][1]
72: end
73: rescue NameError
74: nil
75: end
76: end
# File lib/irb/ext/history.rb, line 85
85: def inspect
86: if @contents.empty?
87: return real_inspect
88: end
89:
90: unless (last = @contents.pop)[1].equal?(self)
91: @contents.push last
92: last = nil
93: end
94: str = @contents.collect{|no, val|
95: if val.equal?(self)
96: "#{no} ...self-history..."
97: else
98: "#{no} #{val.inspect}"
99: end
100: }.join("\n")
101: if str == ""
102: str = "Empty."
103: end
104: @contents.push last if last
105: str
106: end
# File lib/irb/ext/history.rb, line 78
78: def push(no, val)
79: @contents.push [no, val]
80: @contents.shift if @size != 0 && @contents.size > @size
81: end