irb 1.1.0.pre.3 → 1.1.0.pre.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +10 -0
- data/Rakefile +10 -0
- data/bin/console +6 -0
- data/bin/setup +6 -0
- data/doc/irb/irb-tools.rd.ja +184 -0
- data/doc/irb/irb.rd.ja +411 -0
- data/irb.gemspec +56 -1
- data/lib/irb.rb +31 -16
- data/lib/irb/color.rb +27 -12
- data/lib/irb/context.rb +36 -37
- data/lib/irb/ext/history.rb +45 -8
- data/lib/irb/init.rb +9 -9
- data/lib/irb/lc/help-message +7 -5
- data/lib/irb/lc/ja/help-message +6 -3
- data/lib/irb/ruby-lex.rb +11 -4
- data/lib/irb/ruby_logo.aa +38 -0
- data/lib/irb/version.rb +1 -1
- data/lib/irb/workspace.rb +3 -12
- data/man/irb.1 +207 -0
- metadata +11 -4
- data/lib/irb/ruby-token.rb +0 -267
data/irb.gemspec
CHANGED
@@ -16,7 +16,62 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.homepage = "https://github.com/ruby/irb"
|
17
17
|
spec.license = "BSD-2-Clause"
|
18
18
|
|
19
|
-
spec.files = [
|
19
|
+
spec.files = [
|
20
|
+
"Gemfile",
|
21
|
+
"LICENSE.txt",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"bin/console",
|
25
|
+
"bin/setup",
|
26
|
+
"doc/irb/irb-tools.rd.ja",
|
27
|
+
"doc/irb/irb.rd.ja",
|
28
|
+
"exe/irb",
|
29
|
+
"irb.gemspec",
|
30
|
+
"lib/irb.rb",
|
31
|
+
"lib/irb/cmd/chws.rb",
|
32
|
+
"lib/irb/cmd/fork.rb",
|
33
|
+
"lib/irb/cmd/help.rb",
|
34
|
+
"lib/irb/cmd/load.rb",
|
35
|
+
"lib/irb/cmd/nop.rb",
|
36
|
+
"lib/irb/cmd/pushws.rb",
|
37
|
+
"lib/irb/cmd/subirb.rb",
|
38
|
+
"lib/irb/color.rb",
|
39
|
+
"lib/irb/completion.rb",
|
40
|
+
"lib/irb/context.rb",
|
41
|
+
"lib/irb/ext/change-ws.rb",
|
42
|
+
"lib/irb/ext/history.rb",
|
43
|
+
"lib/irb/ext/loader.rb",
|
44
|
+
"lib/irb/ext/multi-irb.rb",
|
45
|
+
"lib/irb/ext/save-history.rb",
|
46
|
+
"lib/irb/ext/tracer.rb",
|
47
|
+
"lib/irb/ext/use-loader.rb",
|
48
|
+
"lib/irb/ext/workspaces.rb",
|
49
|
+
"lib/irb/extend-command.rb",
|
50
|
+
"lib/irb/frame.rb",
|
51
|
+
"lib/irb/help.rb",
|
52
|
+
"lib/irb/init.rb",
|
53
|
+
"lib/irb/input-method.rb",
|
54
|
+
"lib/irb/inspector.rb",
|
55
|
+
"lib/irb/lc/.document",
|
56
|
+
"lib/irb/lc/error.rb",
|
57
|
+
"lib/irb/lc/help-message",
|
58
|
+
"lib/irb/lc/ja/encoding_aliases.rb",
|
59
|
+
"lib/irb/lc/ja/error.rb",
|
60
|
+
"lib/irb/lc/ja/help-message",
|
61
|
+
"lib/irb/locale.rb",
|
62
|
+
"lib/irb/magic-file.rb",
|
63
|
+
"lib/irb/notifier.rb",
|
64
|
+
"lib/irb/output-method.rb",
|
65
|
+
"lib/irb/ruby-lex.rb",
|
66
|
+
"lib/irb/ruby_logo.aa",
|
67
|
+
"lib/irb/slex.rb",
|
68
|
+
"lib/irb/src_encoding.rb",
|
69
|
+
"lib/irb/version.rb",
|
70
|
+
"lib/irb/workspace.rb",
|
71
|
+
"lib/irb/ws-for-case-2.rb",
|
72
|
+
"lib/irb/xmp.rb",
|
73
|
+
"man/irb.1",
|
74
|
+
]
|
20
75
|
spec.bindir = "exe"
|
21
76
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
77
|
spec.require_paths = ["lib"]
|
data/lib/irb.rb
CHANGED
@@ -45,8 +45,8 @@ require "irb/version"
|
|
45
45
|
# irb(main):006:1> end
|
46
46
|
# #=> nil
|
47
47
|
#
|
48
|
-
# The
|
49
|
-
# default if it's installed.
|
48
|
+
# The singleline editor module or multiline editor module can be used with irb.
|
49
|
+
# Use of multiline editor is default if it's installed.
|
50
50
|
#
|
51
51
|
# == Command line options
|
52
52
|
#
|
@@ -61,10 +61,10 @@ require "irb/version"
|
|
61
61
|
# -W[level=2] Same as `ruby -W`
|
62
62
|
# --inspect Use `inspect' for output (default except for bc mode)
|
63
63
|
# --noinspect Don't use inspect for output
|
64
|
-
# --
|
65
|
-
# --
|
66
|
-
# --
|
67
|
-
# --
|
64
|
+
# --multiline Use multiline editor module
|
65
|
+
# --nomultiline Don't use multiline editor module
|
66
|
+
# --singleline Use singleline editor module
|
67
|
+
# --nosingleline Don't use singleline editor module
|
68
68
|
# --colorize Use colorization
|
69
69
|
# --nocolorize Don't use colorization
|
70
70
|
# --prompt prompt-mode
|
@@ -72,7 +72,7 @@ require "irb/version"
|
|
72
72
|
# Switch prompt mode. Pre-defined prompt modes are
|
73
73
|
# `default', `simple', `xmp' and `inf-ruby'
|
74
74
|
# --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
|
75
|
-
# Suppresses --
|
75
|
+
# Suppresses --multiline and --singleline.
|
76
76
|
# --simple-prompt Simple prompt mode
|
77
77
|
# --noprompt No prompt mode
|
78
78
|
# --tracer Display trace for each execution of commands.
|
@@ -100,8 +100,8 @@ require "irb/version"
|
|
100
100
|
# IRB.conf[:IRB_RC] = nil
|
101
101
|
# IRB.conf[:BACK_TRACE_LIMIT]=16
|
102
102
|
# IRB.conf[:USE_LOADER] = false
|
103
|
-
# IRB.conf[:
|
104
|
-
# IRB.conf[:
|
103
|
+
# IRB.conf[:USE_MULTILINE] = nil
|
104
|
+
# IRB.conf[:USE_SINGLELINE] = nil
|
105
105
|
# IRB.conf[:USE_COLORIZE] = true
|
106
106
|
# IRB.conf[:USE_TRACER] = false
|
107
107
|
# IRB.conf[:IGNORE_SIGINT] = true
|
@@ -124,7 +124,7 @@ require "irb/version"
|
|
124
124
|
# === History
|
125
125
|
#
|
126
126
|
# By default, irb will store the last 1000 commands you used in
|
127
|
-
# <code>~/.irb_history</code
|
127
|
+
# <code>IRB.conf[:HISTORY_FILE]</code> (<code>~/.irb_history</code> by default).
|
128
128
|
#
|
129
129
|
# If you want to disable history, add the following to your +.irbrc+:
|
130
130
|
#
|
@@ -132,6 +132,14 @@ require "irb/version"
|
|
132
132
|
#
|
133
133
|
# See IRB::Context#save_history= for more information.
|
134
134
|
#
|
135
|
+
# The history of _resuls_ of commands evaluated is not stored by default,
|
136
|
+
# but can be turned on to be stored with this +.irbrc+ setting:
|
137
|
+
#
|
138
|
+
# IRB.conf[:EVAL_HISTORY] = <number>
|
139
|
+
#
|
140
|
+
# See IRB::Context#eval_history= and History class. The history of command
|
141
|
+
# results is not permanently saved in any file.
|
142
|
+
#
|
135
143
|
# == Customizing the IRB Prompt
|
136
144
|
#
|
137
145
|
# In order to customize the prompt, you can change the following Hash:
|
@@ -274,7 +282,9 @@ require "irb/version"
|
|
274
282
|
# <code>_</code>::
|
275
283
|
# The value command executed, as a local variable
|
276
284
|
# <code>__</code>::
|
277
|
-
# The history of evaluated commands
|
285
|
+
# The history of evaluated commands. Available only if
|
286
|
+
# <code>IRB.conf[:EVAL_HISTORY]</code> is not +nil+ (which is the default).
|
287
|
+
# See also IRB::Context#eval_history= and IRB::History.
|
278
288
|
# <code>__[line_no]</code>::
|
279
289
|
# Returns the evaluation value at the given line number, +line_no+.
|
280
290
|
# If +line_no+ is a negative, the return value +line_no+ many lines before
|
@@ -441,8 +451,8 @@ module IRB
|
|
441
451
|
# parsed as a :method_add_arg and the output won't be suppressed
|
442
452
|
|
443
453
|
# Creates a new irb session
|
444
|
-
def initialize(workspace = nil, input_method = nil
|
445
|
-
@context = Context.new(self, workspace, input_method
|
454
|
+
def initialize(workspace = nil, input_method = nil)
|
455
|
+
@context = Context.new(self, workspace, input_method)
|
446
456
|
@context.main.extend ExtendCommandBundle
|
447
457
|
@signal_status = :IN_IRB
|
448
458
|
@scanner = RubyLex.new
|
@@ -526,7 +536,7 @@ module IRB
|
|
526
536
|
@scanner.each_top_level_statement do |line, line_no|
|
527
537
|
signal_status(:IN_EVAL) do
|
528
538
|
begin
|
529
|
-
line.untaint
|
539
|
+
line.untaint if RUBY_VERSION < '2.7'
|
530
540
|
@context.evaluate(line, line_no, exception: exc)
|
531
541
|
output_value if @context.echo? && (@context.echo_on_assignment? || !assignment_expression?(line))
|
532
542
|
rescue Interrupt => exc
|
@@ -756,7 +766,10 @@ module IRB
|
|
756
766
|
# s-expression where the second selement of the top level array is an
|
757
767
|
# array of parsed expressions. The first element of each expression is the
|
758
768
|
# expression's type.
|
759
|
-
|
769
|
+
verbose, $VERBOSE = $VERBOSE, nil
|
770
|
+
result = ASSIGNMENT_NODE_TYPES.include?(Ripper.sexp(line)&.dig(1,-1,0))
|
771
|
+
$VERBOSE = verbose
|
772
|
+
result
|
760
773
|
end
|
761
774
|
|
762
775
|
ATTR_TTY = "\e[%sm"
|
@@ -850,6 +863,8 @@ class Binding
|
|
850
863
|
IRB.setup(source_location[0], argv: [])
|
851
864
|
workspace = IRB::WorkSpace.new(self)
|
852
865
|
STDOUT.print(workspace.code_around_binding)
|
853
|
-
IRB::Irb.new(workspace)
|
866
|
+
binding_irb = IRB::Irb.new(workspace)
|
867
|
+
binding_irb.context.irb_path = File.expand_path(source_location[0])
|
868
|
+
binding_irb.run(IRB.conf)
|
854
869
|
end
|
855
870
|
end
|
data/lib/irb/color.rb
CHANGED
@@ -30,7 +30,7 @@ module IRB # :nodoc:
|
|
30
30
|
# backtick and regexp as red (string's color, because they're sharing tokens).
|
31
31
|
TOKEN_SEQ_EXPRS = {
|
32
32
|
on_CHAR: [[BLUE, BOLD], ALL],
|
33
|
-
on_backtick: [[RED],
|
33
|
+
on_backtick: [[RED, BOLD], ALL],
|
34
34
|
on_comment: [[BLUE, BOLD], ALL],
|
35
35
|
on_const: [[BLUE, BOLD, UNDERLINE], ALL],
|
36
36
|
on_embexpr_beg: [[RED], ALL],
|
@@ -45,17 +45,18 @@ module IRB # :nodoc:
|
|
45
45
|
on_int: [[BLUE, BOLD], ALL],
|
46
46
|
on_kw: [[GREEN], ALL],
|
47
47
|
on_label: [[MAGENTA], ALL],
|
48
|
-
on_label_end: [[RED],
|
49
|
-
on_qsymbols_beg: [[RED],
|
50
|
-
on_qwords_beg: [[RED],
|
48
|
+
on_label_end: [[RED, BOLD], ALL],
|
49
|
+
on_qsymbols_beg: [[RED, BOLD], ALL],
|
50
|
+
on_qwords_beg: [[RED, BOLD], ALL],
|
51
51
|
on_rational: [[BLUE, BOLD], ALL],
|
52
52
|
on_regexp_beg: [[RED, BOLD], ALL],
|
53
53
|
on_regexp_end: [[RED, BOLD], ALL],
|
54
54
|
on_symbeg: [[YELLOW], ALL],
|
55
|
-
|
55
|
+
on_symbols_beg: [[RED, BOLD], ALL],
|
56
|
+
on_tstring_beg: [[RED, BOLD], ALL],
|
56
57
|
on_tstring_content: [[RED], ALL],
|
57
|
-
on_tstring_end: [[RED],
|
58
|
-
on_words_beg: [[RED],
|
58
|
+
on_tstring_end: [[RED, BOLD], ALL],
|
59
|
+
on_words_beg: [[RED, BOLD], ALL],
|
59
60
|
on_parse_error: [[RED, REVERSE], ALL],
|
60
61
|
compile_error: [[RED, REVERSE], ALL],
|
61
62
|
}
|
@@ -70,16 +71,20 @@ module IRB # :nodoc:
|
|
70
71
|
$stdout.tty? && supported? && (/mswin|mingw/ =~ RUBY_PLATFORM || (ENV.key?('TERM') && ENV['TERM'] != 'dumb'))
|
71
72
|
end
|
72
73
|
|
73
|
-
def inspect_colorable?(obj)
|
74
|
+
def inspect_colorable?(obj, seen: {})
|
74
75
|
case obj
|
75
76
|
when String, Symbol, Regexp, Integer, Float, FalseClass, TrueClass, NilClass
|
76
77
|
true
|
77
78
|
when Hash
|
78
|
-
obj
|
79
|
+
without_circular_ref(obj, seen: seen) do
|
80
|
+
obj.all? { |k, v| inspect_colorable?(k, seen: seen) && inspect_colorable?(v, seen: seen) }
|
81
|
+
end
|
79
82
|
when Array
|
80
|
-
obj
|
83
|
+
without_circular_ref(obj, seen: seen) do
|
84
|
+
obj.all? { |o| inspect_colorable?(o, seen: seen) }
|
85
|
+
end
|
81
86
|
when Range
|
82
|
-
inspect_colorable?(obj.begin) && inspect_colorable?(obj.end)
|
87
|
+
inspect_colorable?(obj.begin, seen: seen) && inspect_colorable?(obj.end, seen: seen)
|
83
88
|
when Module
|
84
89
|
!obj.name.nil?
|
85
90
|
else
|
@@ -132,6 +137,14 @@ module IRB # :nodoc:
|
|
132
137
|
|
133
138
|
private
|
134
139
|
|
140
|
+
def without_circular_ref(obj, seen:, &block)
|
141
|
+
return false if seen.key?(obj.object_id)
|
142
|
+
seen[obj.object_id] = true
|
143
|
+
block.call
|
144
|
+
ensure
|
145
|
+
seen.delete(obj.object_id)
|
146
|
+
end
|
147
|
+
|
135
148
|
# Ripper::Lexer::Elem#state is supported on Ruby 2.5+
|
136
149
|
def supported?
|
137
150
|
return @supported if defined?(@supported)
|
@@ -141,6 +154,7 @@ module IRB # :nodoc:
|
|
141
154
|
def scan(code, allow_last_error:)
|
142
155
|
pos = [1, 0]
|
143
156
|
|
157
|
+
verbose, $VERBOSE = $VERBOSE, nil
|
144
158
|
lexer = Ripper::Lexer.new(code)
|
145
159
|
if lexer.respond_to?(:scan) # Ruby 2.7+
|
146
160
|
lexer.scan.each do |elem|
|
@@ -164,6 +178,7 @@ module IRB # :nodoc:
|
|
164
178
|
yield(elem.event, elem.tok, elem.state)
|
165
179
|
end
|
166
180
|
end
|
181
|
+
$VERBOSE = verbose
|
167
182
|
end
|
168
183
|
|
169
184
|
def dispatch_seq(token, expr, str, in_symbol:)
|
@@ -192,7 +207,7 @@ module IRB # :nodoc:
|
|
192
207
|
def scan_token(token)
|
193
208
|
prev_state = @stack.last
|
194
209
|
case token
|
195
|
-
when :on_symbeg
|
210
|
+
when :on_symbeg, :on_symbols_beg, :on_qsymbols_beg
|
196
211
|
@stack << true
|
197
212
|
when :on_ident, :on_op, :on_const, :on_ivar, :on_cvar, :on_gvar, :on_kw
|
198
213
|
if @stack.last # Pop only when it's Symbol
|
data/lib/irb/context.rb
CHANGED
@@ -25,7 +25,7 @@ module IRB
|
|
25
25
|
# +nil+:: uses stdin or Reidline or Readline
|
26
26
|
# +String+:: uses a File
|
27
27
|
# +other+:: uses this as InputMethod
|
28
|
-
def initialize(irb, workspace = nil, input_method = nil
|
28
|
+
def initialize(irb, workspace = nil, input_method = nil)
|
29
29
|
@irb = irb
|
30
30
|
if workspace
|
31
31
|
@workspace = workspace
|
@@ -39,8 +39,20 @@ module IRB
|
|
39
39
|
@rc = IRB.conf[:RC]
|
40
40
|
@load_modules = IRB.conf[:LOAD_MODULES]
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
if IRB.conf.has_key?(:USE_SINGLELINE)
|
43
|
+
@use_singleline = IRB.conf[:USE_SINGLELINE]
|
44
|
+
elsif IRB.conf.has_key?(:USE_READLINE) # backward compatibility
|
45
|
+
@use_singleline = IRB.conf[:USE_READLINE]
|
46
|
+
else
|
47
|
+
@use_singleline = nil
|
48
|
+
end
|
49
|
+
if IRB.conf.has_key?(:USE_MULTILINE)
|
50
|
+
@use_multiline = IRB.conf[:USE_MULTILINE]
|
51
|
+
elsif IRB.conf.has_key?(:USE_REIDLINE) # backward compatibility
|
52
|
+
@use_multiline = IRB.conf[:USE_REIDLINE]
|
53
|
+
else
|
54
|
+
@use_multiline = nil
|
55
|
+
end
|
44
56
|
@use_colorize = IRB.conf[:USE_COLORIZE]
|
45
57
|
@verbose = IRB.conf[:VERBOSE]
|
46
58
|
@io = nil
|
@@ -67,9 +79,9 @@ module IRB
|
|
67
79
|
case input_method
|
68
80
|
when nil
|
69
81
|
@io = nil
|
70
|
-
case
|
82
|
+
case use_multiline?
|
71
83
|
when nil
|
72
|
-
if STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !
|
84
|
+
if STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline?
|
73
85
|
@io = ReidlineInputMethod.new
|
74
86
|
else
|
75
87
|
@io = nil
|
@@ -80,7 +92,7 @@ module IRB
|
|
80
92
|
@io = ReidlineInputMethod.new
|
81
93
|
end
|
82
94
|
unless @io
|
83
|
-
case
|
95
|
+
case use_singleline?
|
84
96
|
when nil
|
85
97
|
if (defined?(ReadlineInputMethod) && STDIN.tty? &&
|
86
98
|
IRB.conf[:PROMPT_MODE] != :INF_RUBY)
|
@@ -111,12 +123,6 @@ module IRB
|
|
111
123
|
end
|
112
124
|
self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
|
113
125
|
|
114
|
-
if output_method
|
115
|
-
@output_method = output_method
|
116
|
-
else
|
117
|
-
@output_method = StdioOutputMethod.new
|
118
|
-
end
|
119
|
-
|
120
126
|
@echo = IRB.conf[:ECHO]
|
121
127
|
if @echo.nil?
|
122
128
|
@echo = true
|
@@ -161,18 +167,14 @@ module IRB
|
|
161
167
|
# +input_method+ passed to Context.new
|
162
168
|
attr_accessor :irb_path
|
163
169
|
|
164
|
-
# Whether
|
165
|
-
#
|
166
|
-
# A copy of the default <code>IRB.conf[:USE_REIDLINE]</code>
|
170
|
+
# Whether multiline editor mode is enabled or not.
|
167
171
|
#
|
168
|
-
#
|
169
|
-
attr_reader :
|
170
|
-
# Whether
|
172
|
+
# A copy of the default <code>IRB.conf[:USE_MULTILINE]</code>
|
173
|
+
attr_reader :use_multiline
|
174
|
+
# Whether singleline editor mode is enabled or not.
|
171
175
|
#
|
172
|
-
# A copy of the default <code>IRB.conf[:
|
173
|
-
|
174
|
-
# See #use_readline= for more information.
|
175
|
-
attr_reader :use_readline
|
176
|
+
# A copy of the default <code>IRB.conf[:USE_SINGLELINE]</code>
|
177
|
+
attr_reader :use_singleline
|
176
178
|
# Whether colorization is enabled or not.
|
177
179
|
#
|
178
180
|
# A copy of the default <code>IRB.conf[:USE_COLORIZE]</code>
|
@@ -264,10 +266,18 @@ module IRB
|
|
264
266
|
# See IRB@Command+line+options for more command line options.
|
265
267
|
attr_accessor :back_trace_limit
|
266
268
|
|
267
|
-
# Alias for #
|
268
|
-
alias
|
269
|
-
# Alias for #
|
270
|
-
alias
|
269
|
+
# Alias for #use_multiline
|
270
|
+
alias use_multiline? use_multiline
|
271
|
+
# Alias for #use_singleline
|
272
|
+
alias use_singleline? use_singleline
|
273
|
+
# backward compatibility
|
274
|
+
alias use_reidline use_multiline
|
275
|
+
# backward compatibility
|
276
|
+
alias use_reidline? use_multiline
|
277
|
+
# backward compatibility
|
278
|
+
alias use_readline use_singleline
|
279
|
+
# backward compatibility
|
280
|
+
alias use_readline? use_singleline
|
271
281
|
# Alias for #use_colorize
|
272
282
|
alias use_colorize? use_colorize
|
273
283
|
# Alias for #rc
|
@@ -398,17 +408,6 @@ module IRB
|
|
398
408
|
@inspect_mode
|
399
409
|
end
|
400
410
|
|
401
|
-
# Obsolete method.
|
402
|
-
#
|
403
|
-
# Can be set using the +--noreadline+ and +--readline+ command line
|
404
|
-
# options.
|
405
|
-
#
|
406
|
-
# See IRB@Command+line+options for more command line options.
|
407
|
-
def use_readline=(opt)
|
408
|
-
print "This method is obsolete."
|
409
|
-
print "Do nothing."
|
410
|
-
end
|
411
|
-
|
412
411
|
def evaluate(line, line_no, exception: nil) # :nodoc:
|
413
412
|
@line_no = line_no
|
414
413
|
if exception
|
data/lib/irb/ext/history.rb
CHANGED
@@ -31,9 +31,12 @@ module IRB # :nodoc:
|
|
31
31
|
end
|
32
32
|
|
33
33
|
remove_method :eval_history= if method_defined?(:eval_history=)
|
34
|
-
# The command result history limit.
|
34
|
+
# The command result history limit. This method is not available until
|
35
|
+
# #eval_history= was called with non-nil value (directly or via
|
36
|
+
# setting <code>IRB.conf[:EVAL_HISTORY]</code> in <code>.irbrc</code>).
|
35
37
|
attr_reader :eval_history
|
36
|
-
# Sets command result history limit.
|
38
|
+
# Sets command result history limit. Default value is set from
|
39
|
+
# <code>IRB.conf[:EVAL_HISTORY]</code>.
|
37
40
|
#
|
38
41
|
# +no+ is an Integer or +nil+.
|
39
42
|
#
|
@@ -42,6 +45,9 @@ module IRB # :nodoc:
|
|
42
45
|
# If +no+ is 0, the number of history items is unlimited.
|
43
46
|
#
|
44
47
|
# If +no+ is +nil+, execution result history isn't used (default).
|
48
|
+
#
|
49
|
+
# History values are available via <code>__</code> variable, see
|
50
|
+
# IRB::History.
|
45
51
|
def eval_history=(no)
|
46
52
|
if no
|
47
53
|
if defined?(@eval_history) && @eval_history
|
@@ -59,20 +65,51 @@ module IRB # :nodoc:
|
|
59
65
|
end
|
60
66
|
end
|
61
67
|
|
62
|
-
|
63
|
-
|
64
|
-
|
68
|
+
# Represents history of results of previously evaluated commands.
|
69
|
+
#
|
70
|
+
# Available via <code>__</code> variable, only if <code>IRB.conf[:EVAL_HISTORY]</code>
|
71
|
+
# or <code>IRB::CurrentContext().eval_history</code> is non-nil integer value
|
72
|
+
# (by default it is +nil+).
|
73
|
+
#
|
74
|
+
# Example (in `irb`):
|
75
|
+
#
|
76
|
+
# # Initialize history
|
77
|
+
# IRB::CurrentContext().eval_history = 10
|
78
|
+
# # => 10
|
79
|
+
#
|
80
|
+
# # Perform some commands...
|
81
|
+
# 1 + 2
|
82
|
+
# # => 3
|
83
|
+
# puts 'x'
|
84
|
+
# # x
|
85
|
+
# # => nil
|
86
|
+
# raise RuntimeError
|
87
|
+
# # ...error raised
|
88
|
+
#
|
89
|
+
# # Inspect history (format is "<item number> <evaluated value>":
|
90
|
+
# __
|
91
|
+
# # => 1 10
|
92
|
+
# # 2 3
|
93
|
+
# # 3 nil
|
94
|
+
#
|
95
|
+
# __[1]
|
96
|
+
# # => 10
|
97
|
+
#
|
98
|
+
class History
|
99
|
+
|
100
|
+
def initialize(size = 16) # :nodoc:
|
65
101
|
@size = size
|
66
102
|
@contents = []
|
67
103
|
end
|
68
104
|
|
69
|
-
def size(size)
|
105
|
+
def size(size) # :nodoc:
|
70
106
|
if size != 0 && size < @size
|
71
107
|
@contents = @contents[@size - size .. @size]
|
72
108
|
end
|
73
109
|
@size = size
|
74
110
|
end
|
75
111
|
|
112
|
+
# Get one item of the content (both positive and negative indexes work).
|
76
113
|
def [](idx)
|
77
114
|
begin
|
78
115
|
if idx >= 0
|
@@ -85,14 +122,14 @@ module IRB # :nodoc:
|
|
85
122
|
end
|
86
123
|
end
|
87
124
|
|
88
|
-
def push(no, val)
|
125
|
+
def push(no, val) # :nodoc:
|
89
126
|
@contents.push [no, val]
|
90
127
|
@contents.shift if @size != 0 && @contents.size > @size
|
91
128
|
end
|
92
129
|
|
93
130
|
alias real_inspect inspect
|
94
131
|
|
95
|
-
def inspect
|
132
|
+
def inspect # :nodoc:
|
96
133
|
if @contents.empty?
|
97
134
|
return real_inspect
|
98
135
|
end
|