DEFINITIONS
This source file includes following functions.
1 #
2 # history.rb -
3 # $Release Version: 0.9$
4 # $Revision: 1.1 $
5 # $Date: 2002/07/09 11:17:17 $
6 # by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
7 #
8 # --
9 #
10 #
11 #
12
13 module IRB
14
15 class Context
16
17 NOPRINTING_IVARS.push "@eval_history_values"
18
19 alias _set_last_value set_last_value
20
21 def set_last_value(value)
22 _set_last_value(value)
23
24 @workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
25 if @eval_history #and !@eval_history_values.equal?(llv)
26 @eval_history_values.push @line_no, @last_value
27 @workspace.evaluate self, "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
28 end
29
30 @last_value
31 end
32
33 attr_reader :eval_history
34 def eval_history=(no)
35 if no
36 if @eval_history
37 @eval_history_values.size(no)
38 else
39 @eval_history_values = History.new(no)
40 IRB.conf[:__TMP__EHV__] = @eval_history_values
41 @workspace.evaluate(self, "__ = IRB.conf[:__TMP__EHV__]")
42 IRB.conf.delete(:__TMP_EHV__)
43 end
44 else
45 @eval_history_values = nil
46 end
47 @eval_history = no
48 end
49 end
50
51 class History
52 @RCS_ID='-$Id: history.rb,v 1.1 2002/07/09 11:17:17 keiju Exp $-'
53
54 def initialize(size = 16)
55 @size = size
56 @contents = []
57 end
58
59 def size(size)
60 if size != 0 && size < @size
61 @contents = @contents[@size - size .. @size]
62 end
63 @size = size
64 end
65
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
77
78 def push(no, val)
79 @contents.push [no, val]
80 @contents.shift if @size != 0 && @contents.size > @size
81 end
82
83 alias real_inspect inspect
84
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
107 end
108 end
109
110