irb 1.13.2 → 1.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +13 -293
- data/Rakefile +4 -6
- data/irb.gemspec +5 -3
- data/lib/irb/color.rb +1 -0
- data/lib/irb/color_printer.rb +10 -9
- data/lib/irb/command/base.rb +12 -14
- data/lib/irb/command/cd.rb +51 -0
- data/lib/irb/command/copy.rb +73 -0
- data/lib/irb/command/debug.rb +8 -6
- data/lib/irb/command/help.rb +1 -1
- data/lib/irb/command/history.rb +1 -1
- data/lib/irb/command/internal_helpers.rb +1 -1
- data/lib/irb/command/ls.rb +23 -11
- data/lib/irb/completion.rb +41 -14
- data/lib/irb/context.rb +131 -54
- data/lib/irb/debug/ui.rb +2 -4
- data/lib/irb/debug.rb +7 -10
- data/lib/irb/default_commands.rb +22 -8
- data/lib/irb/easter-egg.rb +10 -6
- data/lib/irb/history.rb +84 -55
- data/lib/irb/init.rb +4 -2
- data/lib/irb/input-method.rb +31 -24
- data/lib/irb/inspector.rb +42 -36
- data/lib/irb/lc/ja/help-message +4 -4
- data/lib/irb/nesting_parser.rb +196 -194
- data/lib/irb/pager.rb +129 -7
- data/lib/irb/ruby-lex.rb +84 -82
- data/lib/irb/ruby_logo.aa +75 -37
- data/lib/irb/source_finder.rb +3 -4
- data/lib/irb/statement.rb +22 -1
- data/lib/irb/version.rb +2 -2
- data/lib/irb/workspace.rb +13 -31
- data/lib/irb.rb +75 -947
- data/man/irb.1 +37 -2
- metadata +20 -8
- data/.document +0 -4
data/lib/irb/ruby-lex.rb
CHANGED
@@ -36,29 +36,6 @@ module IRB
|
|
36
36
|
:massign,
|
37
37
|
]
|
38
38
|
|
39
|
-
class TerminateLineInput < StandardError
|
40
|
-
def initialize
|
41
|
-
super("Terminate Line Input")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.compile_with_errors_suppressed(code, line_no: 1)
|
46
|
-
begin
|
47
|
-
result = yield code, line_no
|
48
|
-
rescue ArgumentError
|
49
|
-
# Ruby can issue an error for the code if there is an
|
50
|
-
# incomplete magic comment for encoding in it. Force an
|
51
|
-
# expression with a new line before the code in this
|
52
|
-
# case to prevent magic comment handling. To make sure
|
53
|
-
# line numbers in the lexed code remain the same,
|
54
|
-
# decrease the line number by one.
|
55
|
-
code = ";\n#{code}"
|
56
|
-
line_no -= 1
|
57
|
-
result = yield code, line_no
|
58
|
-
end
|
59
|
-
result
|
60
|
-
end
|
61
|
-
|
62
39
|
ERROR_TOKENS = [
|
63
40
|
:on_parse_error,
|
64
41
|
:compile_error,
|
@@ -68,70 +45,102 @@ module IRB
|
|
68
45
|
:on_param_error
|
69
46
|
]
|
70
47
|
|
71
|
-
|
72
|
-
|
48
|
+
LTYPE_TOKENS = %i[
|
49
|
+
on_heredoc_beg on_tstring_beg
|
50
|
+
on_regexp_beg on_symbeg on_backtick
|
51
|
+
on_symbols_beg on_qsymbols_beg
|
52
|
+
on_words_beg on_qwords_beg
|
53
|
+
]
|
54
|
+
|
55
|
+
class TerminateLineInput < StandardError
|
56
|
+
def initialize
|
57
|
+
super("Terminate Line Input")
|
58
|
+
end
|
73
59
|
end
|
74
60
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
61
|
+
class << self
|
62
|
+
def compile_with_errors_suppressed(code, line_no: 1)
|
63
|
+
begin
|
64
|
+
result = yield code, line_no
|
65
|
+
rescue ArgumentError
|
66
|
+
# Ruby can issue an error for the code if there is an
|
67
|
+
# incomplete magic comment for encoding in it. Force an
|
68
|
+
# expression with a new line before the code in this
|
69
|
+
# case to prevent magic comment handling. To make sure
|
70
|
+
# line numbers in the lexed code remain the same,
|
71
|
+
# decrease the line number by one.
|
72
|
+
code = ";\n#{code}"
|
73
|
+
line_no -= 1
|
74
|
+
result = yield code, line_no
|
75
|
+
end
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
def generate_local_variables_assign_code(local_variables)
|
80
|
+
"#{local_variables.join('=')}=nil;" unless local_variables.empty?
|
82
81
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
tokens.
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
82
|
+
|
83
|
+
# Some part of the code is not included in Ripper's token.
|
84
|
+
# Example: DATA part, token after heredoc_beg when heredoc has unclosed embexpr.
|
85
|
+
# With interpolated tokens, tokens.map(&:tok).join will be equal to code.
|
86
|
+
def interpolate_ripper_ignored_tokens(code, tokens)
|
87
|
+
line_positions = [0]
|
88
|
+
code.lines.each do |line|
|
89
|
+
line_positions << line_positions.last + line.bytesize
|
90
|
+
end
|
91
|
+
prev_byte_pos = 0
|
92
|
+
interpolated = []
|
93
|
+
prev_line = 1
|
94
|
+
tokens.each do |t|
|
95
|
+
line, col = t.pos
|
96
|
+
byte_pos = line_positions[line - 1] + col
|
97
|
+
if prev_byte_pos < byte_pos
|
98
|
+
tok = code.byteslice(prev_byte_pos...byte_pos)
|
99
|
+
pos = [prev_line, prev_byte_pos - line_positions[prev_line - 1]]
|
100
|
+
interpolated << Ripper::Lexer::Elem.new(pos, :on_ignored_by_ripper, tok, 0)
|
101
|
+
prev_line += tok.count("\n")
|
102
|
+
end
|
103
|
+
interpolated << t
|
104
|
+
prev_byte_pos = byte_pos + t.tok.bytesize
|
105
|
+
prev_line += t.tok.count("\n")
|
106
|
+
end
|
107
|
+
if prev_byte_pos < code.bytesize
|
108
|
+
tok = code.byteslice(prev_byte_pos..)
|
91
109
|
pos = [prev_line, prev_byte_pos - line_positions[prev_line - 1]]
|
92
110
|
interpolated << Ripper::Lexer::Elem.new(pos, :on_ignored_by_ripper, tok, 0)
|
93
|
-
prev_line += tok.count("\n")
|
94
111
|
end
|
95
|
-
interpolated
|
96
|
-
prev_byte_pos = byte_pos + t.tok.bytesize
|
97
|
-
prev_line += t.tok.count("\n")
|
98
|
-
end
|
99
|
-
if prev_byte_pos < code.bytesize
|
100
|
-
tok = code.byteslice(prev_byte_pos..)
|
101
|
-
pos = [prev_line, prev_byte_pos - line_positions[prev_line - 1]]
|
102
|
-
interpolated << Ripper::Lexer::Elem.new(pos, :on_ignored_by_ripper, tok, 0)
|
112
|
+
interpolated
|
103
113
|
end
|
104
|
-
interpolated
|
105
|
-
end
|
106
114
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
115
|
+
def ripper_lex_without_warning(code, local_variables: [])
|
116
|
+
verbose, $VERBOSE = $VERBOSE, nil
|
117
|
+
lvars_code = generate_local_variables_assign_code(local_variables)
|
118
|
+
original_code = code
|
119
|
+
if lvars_code
|
120
|
+
code = "#{lvars_code}\n#{code}"
|
121
|
+
line_no = 0
|
122
|
+
else
|
123
|
+
line_no = 1
|
124
|
+
end
|
117
125
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
126
|
+
compile_with_errors_suppressed(code, line_no: line_no) do |inner_code, line_no|
|
127
|
+
lexer = Ripper::Lexer.new(inner_code, '-', line_no)
|
128
|
+
tokens = []
|
129
|
+
lexer.scan.each do |t|
|
130
|
+
next if t.pos.first == 0
|
131
|
+
prev_tk = tokens.last
|
132
|
+
position_overlapped = prev_tk && t.pos[0] == prev_tk.pos[0] && t.pos[1] < prev_tk.pos[1] + prev_tk.tok.bytesize
|
133
|
+
if position_overlapped
|
134
|
+
tokens[-1] = t if ERROR_TOKENS.include?(prev_tk.event) && !ERROR_TOKENS.include?(t.event)
|
135
|
+
else
|
136
|
+
tokens << t
|
137
|
+
end
|
129
138
|
end
|
139
|
+
interpolate_ripper_ignored_tokens(original_code, tokens)
|
130
140
|
end
|
131
|
-
|
141
|
+
ensure
|
142
|
+
$VERBOSE = verbose
|
132
143
|
end
|
133
|
-
ensure
|
134
|
-
$VERBOSE = verbose
|
135
144
|
end
|
136
145
|
|
137
146
|
def check_code_state(code, local_variables:)
|
@@ -391,13 +400,6 @@ module IRB
|
|
391
400
|
end
|
392
401
|
end
|
393
402
|
|
394
|
-
LTYPE_TOKENS = %i[
|
395
|
-
on_heredoc_beg on_tstring_beg
|
396
|
-
on_regexp_beg on_symbeg on_backtick
|
397
|
-
on_symbols_beg on_qsymbols_beg
|
398
|
-
on_words_beg on_qwords_beg
|
399
|
-
]
|
400
|
-
|
401
403
|
def ltype_from_open_tokens(opens)
|
402
404
|
start_token = opens.reverse_each.find do |tok|
|
403
405
|
LTYPE_TOKENS.include?(tok.event)
|
data/lib/irb/ruby_logo.aa
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
TYPE:
|
1
|
+
TYPE: ASCII_LARGE
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
3
|
+
,,,;;;;;;;;;;;;;;;;;;;;;;,,
|
4
|
+
,,,;;;;;;;;;,, ,;;;' ''';;,
|
5
|
+
,,;;;''' ';;;, ,,;;'' '';,
|
6
|
+
,;;'' ;;;;;;;;,,,,,, ';;
|
7
|
+
,;;'' ;;;;';;;'''';;;;;;;;;,,,;;
|
8
|
+
,,;'' ;;;; ';;, ''''';;,
|
9
|
+
,;;' ;;;' ';;, ;;
|
10
|
+
,;;' ,;;; '';,, ;;
|
11
|
+
,;;' ;;; ';;, ,;;
|
12
|
+
;;' ;;;' '';,, ;;;
|
13
|
+
,;' ;;;; ';;, ;;'
|
14
|
+
,;;' ,;;;;' ,,,,,,,,,,,,;;;;;
|
15
|
+
,;' ,;;;;;;;;;;;;;;;;;;;;'''''''';;;
|
16
|
+
;;' ,;;;;;;;;;,, ;;;;
|
17
|
+
;;' ,;;;'' ;;, ';;,, ,;;;;
|
18
|
+
;;' ,;;;' ;; '';;, ,;';;;
|
19
|
+
;;' ,;;;' ;;, '';;,, ,;',;;;
|
20
|
+
,;;; ,;;;' ;; '';;,, ,;' ;;;'
|
21
|
+
;;;; ,,;;;' ;;, ';;;' ;;;
|
22
|
+
,;;; ,;;;;' ;; ,;;; ;;;
|
23
|
+
;;;;; ,,;;;;;' ;;, ,;';; ;;;
|
24
|
+
;;;;;, ,,;;;;;;;' ;; ,;;' ;;; ;;;
|
25
|
+
;;;;;;;,,,,,,,;;;;;;;;;;;;;;,,, ;;, ,;' ;; ;;;
|
26
|
+
;;' ;;;;;;;;;;'''' ,;';; ''';;;;,,, ;; ,;; ;; ;;;
|
27
|
+
;; ;;;'' ;; ';; ''';;;;,,,, ;;, ,;;' ;;, ;;
|
28
|
+
;; ;;;;, ;;' ';; ''';;;;,,;;;;' ';; ;;
|
29
|
+
;;;;;;';, ,;; ;; '';;;;, ;;,;;
|
30
|
+
;;; ;; ;;, ;; ;; ,;;' ';;, ;;;;;
|
31
|
+
;; ;;; ;;, ;;' ;; ,,;'' ';;, ;;;;;
|
32
|
+
;; ;; ;; ;; ;; ,;;' '';, ;;;;
|
33
|
+
;;,;; ;; ;;' ;; ,;;'' ';,, ;;;'
|
34
|
+
;;;; ';; ,;; ;;,,;;'' ';;, ;;;
|
35
|
+
';;; ';; ;; ,;;;;;;;;;;;;;,,,,,,,,,,,, ';;;;;
|
36
|
+
';, ';,;;' ,,,;;'' '''''''';;;;;;;;;;;;;;;;;;;
|
37
|
+
';;,,, ;;;; ,,,,;;;;;;,,,,,;;;;;;;;;;;;;;;;;;;''''''''''''''
|
38
|
+
''';;;;;;;;;;;;;;'''''''''''''''
|
39
39
|
TYPE: ASCII
|
40
40
|
,,,;;;;''''';;;'';,
|
41
41
|
,,;'' ';;,;;; ',
|
@@ -57,6 +57,44 @@ TYPE: ASCII
|
|
57
57
|
;;; '; ;' ';,,'' ';,;;
|
58
58
|
'; ';,; ,,;''''''''';;;;;;,,;;;
|
59
59
|
';,,;;,,;;;;;;;;;;''''''''''''''
|
60
|
+
TYPE: UNICODE_LARGE
|
61
|
+
|
62
|
+
⣀⣤⣴⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣤⣄⡀
|
63
|
+
⢀⣀⣤⣴⣾⣿⣿⣿⠿⣿⣿⣿⣿⣦⣀ ⢀⣤⣶⣿⠿⠛⠁⠈⠉⠙⠻⢿⣷⣦⡀
|
64
|
+
⢀⣠⣴⣾⡿⠿⠛⠉⠉ ⠈⠙⢿⣿⣷⣤⡀ ⣠⣴⣾⡿⠟⠉ ⠉⠻⣿⣦
|
65
|
+
⢀⣤⣶⣿⠟⠋⠁ ⢿⣿⣿⣿⣿⣿⣿⣧⣤⣤⣤⣀⣀⣀⡀ ⠘⢿⣷⡀
|
66
|
+
⢀⣠⣾⡿⠟⠉ ⢸⣿⣿⣿⠟⢿⣿⣯⡙⠛⠛⠛⠿⠿⠿⢿⣿⣿⣶⣶⣶⣦⣤⣬⣿⣧
|
67
|
+
⣠⣴⣿⠟⠋ ⢸⣿⣿⡿ ⠈⠻⣿⣶⣄ ⠉⠉⠉⠙⠛⢻⣿⡆
|
68
|
+
⣠⣾⡿⠛⠁ ⣼⣿⣿⠃ ⠈⠙⢿⣷⣤⡀ ⠈⣿⡇
|
69
|
+
⣠⣾⡿⠋ ⢠⣿⣿⡏ ⠙⠻⣿⣦⣀ ⣿⡇
|
70
|
+
⣠⣾⡿⠋ ⢀⣿⣿⣿ ⠈⠛⢿⣷⣄⡀ ⢠⣿⡇
|
71
|
+
⢀⣾⡿⠋ ⢀⣾⣿⣿⠇ ⠙⠻⣿⣦⣀ ⢸⣿⡇
|
72
|
+
⢀⣴⣿⠟⠁ ⢀⣾⣿⣿⡟ ⠈⠻⢿⣷⣄ ⣾⣿⠇
|
73
|
+
⢠⣾⡿⠃ ⣠⣿⣿⣿⣿⠃ ⣀⣀⣀⣀⣀⣀⣀⣀⣤⣤⣤⣤⣽⣿⣿⣿⣿
|
74
|
+
⣰⣿⠟ ⣴⣿⣿⣿⣿⣿⣶⣶⣿⣿⣿⣿⣿⠿⠿⠿⠿⠿⠿⠿⠿⠛⠛⠛⠛⠛⠛⠛⠛⣿⣿⣿
|
75
|
+
⣼⣿⠏ ⢠⣾⣿⣿⣿⡿⣿⣿⢿⣷⣦⣄ ⣼⣿⣿⣿
|
76
|
+
⣼⣿⠃ ⢀⣴⣿⣿⣿⠟⠋ ⢸⣿⡆⠈⠛⠿⣿⣦⣄⡀ ⣰⣿⣿⣿⡇
|
77
|
+
⢀⣾⣿⠃ ⢀⣴⣿⣿⣿⠟⠁ ⣿⣷ ⠈⠙⠻⣿⣶⣄⡀ ⣰⣿⠟⣿⣿⡇
|
78
|
+
⢀⣾⣿⠇ ⢀⣴⣿⣿⣿⠟⠁ ⢸⣿⡆ ⠙⠻⢿⣷⣤⣀ ⣰⣿⠏⢠⣿⣿⡇
|
79
|
+
⢠⣿⣿⡟ ⢀⣴⣿⣿⡿⠛⠁ ⣿⣷ ⠉⠻⢿⣷⣦⣀ ⣴⣿⠏ ⢸⣿⣿⠃
|
80
|
+
⣿⣿⣿⡇ ⣠⣴⣿⣿⡿⠋ ⢸⣿⡆ ⠈⠛⢿⣿⣿⠃ ⢸⣿⣿
|
81
|
+
⢠⣿⣿⣿ ⢀⣴⣾⣿⣿⡿⠋ ⠈⣿⣧ ⢠⣾⣿⣿ ⢸⣿⣿
|
82
|
+
⢸⣿⣿⣿⡇ ⣀⣴⣾⣿⣿⣿⡿⠋ ⢹⣿⡆ ⣴⣿⠟⢹⣿⡀ ⢸⣿⡿
|
83
|
+
⢸⣿⡟⣿⣿⣄ ⣀⣤⣶⣿⣿⣿⣿⣿⡟⠉ ⠈⣿⣷ ⢠⣾⡿⠋ ⢸⣿⡇ ⣼⣿⡇
|
84
|
+
⢸⣿⡇⢹⣿⣿⣷⣦⣤⣤⣤⣤⣤⣴⣶⣾⣿⣿⣿⣿⡿⠿⣿⣿⣿⣿⣷⣶⣤⣤⣀⡀ ⢹⣿⡆ ⢀⣴⣿⠟ ⣿⣧ ⣿⣿⡇
|
85
|
+
⢸⣿⠃ ⢿⣿⣿⣿⣿⣿⣿⡿⠿⠿⠛⠛⠉⠉⠁ ⢰⣿⠟⣿⣷⡀⠉⠙⠛⠿⢿⣿⣶⣦⣤⣀⡀ ⠈⣿⣷ ⣠⣿⡿⠁ ⢿⣿ ⣿⣿⡇
|
86
|
+
⢸⣿ ⢀⣾⣿⣿⠋⠉⠁ ⢀⣿⡿ ⠘⣿⣷⡀ ⠉⠙⠛⠿⠿⣿⣶⣦⣤⣄⣀ ⢹⣿⡄ ⣠⣾⡿⠋ ⢸⣿⡆ ⣿⣿
|
87
|
+
⣸⣿⢀⣾⣿⣿⣿⣆ ⣸⣿⠃ ⠘⢿⣷⡀ ⠈⠉⠛⠻⠿⣿⣷⣶⣤⣌⣿⣷⣾⡿⠋ ⠘⣿⡇ ⣿⣿
|
88
|
+
⣿⣿⣾⡿⣿⡿⠹⣿⡆ ⢠⣿⡏ ⠈⢿⣷⡀ ⠈⠉⠙⣻⣿⣿⣿⣀ ⣿⣷⢰⣿⣿
|
89
|
+
⣿⣿⡿⢁⣿⡇ ⢻⣿⡄ ⣾⣿ ⠈⢿⣷⡀ ⢀⣤⣾⡿⠋⠈⠻⢿⣷⣄ ⢻⣿⢸⣿⡟
|
90
|
+
⣿⣿⠁⢸⣿⡇ ⢻⣿⡄ ⢸⣿⠇ ⠈⢿⣷⡀ ⣀⣴⣿⠟⠋ ⠙⢿⣷⣤⡀ ⢸⣿⣿⣿⡇
|
91
|
+
⣿⣿ ⢸⣿⠁ ⠈⢿⣷⡀ ⢀⣿⡟ ⠈⢿⣷⡀ ⢀⣤⣾⡿⠛⠁ ⠙⠻⣿⣦⡀ ⠈⣿⣿⣿⡇
|
92
|
+
⢸⣿⡄⣿⣿ ⠈⣿⣷⡀ ⣼⣿⠃ ⠈⢿⣷⡀ ⢀⣠⣶⣿⠟⠋ ⠈⠻⣿⣦⣄ ⣿⣿⣿⠇
|
93
|
+
⠈⣿⣷⣿⡿ ⠘⣿⣧ ⢠⣿⡏ ⠈⢿⣷⣄⣤⣶⣿⠟⠋ ⠈⠛⢿⣷⣄ ⢸⣿⣿
|
94
|
+
⠘⣿⣿⡇ ⠘⣿⣧ ⣾⣿ ⢀⣠⣼⣿⣿⣿⣿⣿⣷⣶⣶⣶⣶⣶⣶⣤⣤⣤⣤⣤⣤⣀⣀⣀⣀⣀⣀⡀ ⠙⢿⣷⣼⣿⣿
|
95
|
+
⠈⠻⣿⣦⡀ ⠹⣿⣆⢸⣿⠇ ⣀⣠⣴⣾⡿⠟⠋⠁ ⠉⠉⠉⠉⠉⠉⠛⠛⣛⣛⣛⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⡿
|
96
|
+
⠈⠻⢿⣷⣦⣄⣀⡀ ⢹⣿⣿⡟ ⢀⣀⣀⣤⣤⣶⣾⣿⣿⣿⣯⣥⣤⣤⣤⣤⣶⣶⣶⣶⣶⣶⣶⣾⣿⣿⣿⣿⠿⠿⠿⠿⠿⠿⠿⠟⠛⠛⠛⠛⠛⠛⠛⠉⠉⠉⠉⠉⠉
|
97
|
+
⠉⠙⠛⠿⠿⠿⣿⣿⣿⣿⠿⠿⠿⠿⠿⠿⠿⠛⠛⠛⠛⠛⠛⠛⠋⠉⠉⠉⠉⠉⠉⠉
|
60
98
|
TYPE: UNICODE
|
61
99
|
⣀⣤⣴⣾⣿⣿⣿⡛⠛⠛⠛⠛⣻⣿⠿⠛⠛⠶⣤⡀
|
62
100
|
⣀⣴⠾⠛⠉⠁ ⠙⣿⣶⣤⣶⣟⣉ ⠈⠻⣦
|
data/lib/irb/source_finder.rb
CHANGED
@@ -100,7 +100,7 @@ module IRB
|
|
100
100
|
Source.new(file, line)
|
101
101
|
elsif method
|
102
102
|
# Method defined with eval, probably in IRB session
|
103
|
-
source = RubyVM::
|
103
|
+
source = RubyVM::InstructionSequence.of(method)&.script_lines&.join rescue nil
|
104
104
|
Source.new(file, line, source)
|
105
105
|
end
|
106
106
|
rescue EvaluationError
|
@@ -125,9 +125,8 @@ module IRB
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def eval_receiver_or_owner(code)
|
128
|
-
|
129
|
-
|
130
|
-
rescue NameError
|
128
|
+
@irb_context.workspace.binding.eval(code)
|
129
|
+
rescue Exception
|
131
130
|
raise EvaluationError
|
132
131
|
end
|
133
132
|
|
data/lib/irb/statement.rb
CHANGED
@@ -54,6 +54,27 @@ module IRB
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
class IncorrectAlias < Statement
|
58
|
+
attr_reader :message
|
59
|
+
|
60
|
+
def initialize(message)
|
61
|
+
@code = ""
|
62
|
+
@message = message
|
63
|
+
end
|
64
|
+
|
65
|
+
def should_be_handled_by_debugger?
|
66
|
+
false
|
67
|
+
end
|
68
|
+
|
69
|
+
def is_assignment?
|
70
|
+
false
|
71
|
+
end
|
72
|
+
|
73
|
+
def suppresses_echo?
|
74
|
+
true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
57
78
|
class Command < Statement
|
58
79
|
attr_reader :command_class, :arg
|
59
80
|
|
@@ -68,7 +89,7 @@ module IRB
|
|
68
89
|
end
|
69
90
|
|
70
91
|
def suppresses_echo?
|
71
|
-
|
92
|
+
true
|
72
93
|
end
|
73
94
|
|
74
95
|
def should_be_handled_by_debugger?
|
data/lib/irb/version.rb
CHANGED
data/lib/irb/workspace.rb
CHANGED
@@ -4,8 +4,6 @@
|
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
5
5
|
#
|
6
6
|
|
7
|
-
require "delegate"
|
8
|
-
|
9
7
|
require_relative "helper_method"
|
10
8
|
|
11
9
|
IRB::TOPLEVEL_BINDING = binding
|
@@ -16,7 +14,7 @@ module IRB # :nodoc:
|
|
16
14
|
# set self to main if specified, otherwise
|
17
15
|
# inherit main from TOPLEVEL_BINDING.
|
18
16
|
def initialize(*main)
|
19
|
-
if main[0]
|
17
|
+
if Binding === main[0]
|
20
18
|
@binding = main.shift
|
21
19
|
elsif IRB.conf[:SINGLE_IRB]
|
22
20
|
@binding = TOPLEVEL_BINDING
|
@@ -70,37 +68,16 @@ EOF
|
|
70
68
|
unless main.empty?
|
71
69
|
case @main
|
72
70
|
when Module
|
73
|
-
@binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
71
|
+
@binding = eval("::IRB.conf[:__MAIN__].module_eval('::Kernel.binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
74
72
|
else
|
75
73
|
begin
|
76
|
-
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
74
|
+
@binding = eval("::IRB.conf[:__MAIN__].instance_eval('::Kernel.binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
77
75
|
rescue TypeError
|
78
76
|
fail CantChangeBinding, @main.inspect
|
79
77
|
end
|
80
78
|
end
|
81
79
|
end
|
82
80
|
|
83
|
-
case @main
|
84
|
-
when Object
|
85
|
-
use_delegator = @main.frozen?
|
86
|
-
else
|
87
|
-
use_delegator = true
|
88
|
-
end
|
89
|
-
|
90
|
-
if use_delegator
|
91
|
-
@main = SimpleDelegator.new(@main)
|
92
|
-
IRB.conf[:__MAIN__] = @main
|
93
|
-
@main.singleton_class.class_eval do
|
94
|
-
private
|
95
|
-
define_method(:binding, Kernel.instance_method(:binding))
|
96
|
-
define_method(:local_variables, Kernel.instance_method(:local_variables))
|
97
|
-
# Define empty method to avoid delegator warning, will be overridden.
|
98
|
-
define_method(:exit) {|*a, &b| }
|
99
|
-
define_method(:exit!) {|*a, &b| }
|
100
|
-
end
|
101
|
-
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, *@binding.source_location)
|
102
|
-
end
|
103
|
-
|
104
81
|
@binding.local_variable_set(:_, nil)
|
105
82
|
end
|
106
83
|
|
@@ -111,6 +88,9 @@ EOF
|
|
111
88
|
attr_reader :main
|
112
89
|
|
113
90
|
def load_helper_methods_to_main
|
91
|
+
# Do not load helper methods to frozen objects and BasicObject
|
92
|
+
return unless Object === @main && !@main.frozen?
|
93
|
+
|
114
94
|
ancestors = class<<main;ancestors;end
|
115
95
|
main.extend ExtendCommandBundle if !ancestors.include?(ExtendCommandBundle)
|
116
96
|
main.extend HelpersContainer if !ancestors.include?(HelpersContainer)
|
@@ -176,11 +156,13 @@ EOF
|
|
176
156
|
end
|
177
157
|
|
178
158
|
module HelpersContainer
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
159
|
+
class << self
|
160
|
+
def install_helper_methods
|
161
|
+
HelperMethod.helper_methods.each do |name, helper_method_class|
|
162
|
+
define_method name do |*args, **opts, &block|
|
163
|
+
helper_method_class.instance.execute(*args, **opts, &block)
|
164
|
+
end unless method_defined?(name)
|
165
|
+
end
|
184
166
|
end
|
185
167
|
end
|
186
168
|
|