Class: IRB::History

Inherits:
Object show all
Defined in:
lib/irb/ext/history.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(size = 16) ⇒ History

Returns a new instance of History.



64
65
66
67
# File 'lib/irb/ext/history.rb', line 64

def initialize(size = 16)
  @size = size
  @contents = []
end

Instance Method Details

#[](idx) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/irb/ext/history.rb', line 76

def [](idx)
  begin
	if idx >= 0
	  @contents.find{|no, val| no == idx}[1]
	else
	  @contents[idx][1]
	end
  rescue NameError
	nil
  end
end

#inspectObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/irb/ext/history.rb', line 95

def inspect
  if @contents.empty?
	return real_inspect
  end

  unless (last = @contents.pop)[1].equal?(self)
	@contents.push last
	last = nil
  end
  str = @contents.collect{|no, val|
	if val.equal?(self)
	  "#{no} ...self-history..."
	else
	  "#{no} #{val.inspect}"
	end
  }.join("\n")
  if str == ""
	str = "Empty."
  end
  @contents.push last if last
  str
end

#push(no, val) ⇒ Object



88
89
90
91
# File 'lib/irb/ext/history.rb', line 88

def push(no, val)
  @contents.push [no, val]
  @contents.shift if @size != 0 && @contents.size > @size
end

#real_inspectObject



93
# File 'lib/irb/ext/history.rb', line 93

alias real_inspect inspect

#size(size) ⇒ Object



69
70
71
72
73
74
# File 'lib/irb/ext/history.rb', line 69

def size(size)
  if size != 0 && size < @size
	@contents = @contents[@size - size .. @size]
  end
  @size = size
end