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.
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
- def self.generate_local_variables_assign_code(local_variables)
72
- "#{local_variables.join('=')}=nil;" unless local_variables.empty?
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
- # Some part of the code is not included in Ripper's token.
76
- # Example: DATA part, token after heredoc_beg when heredoc has unclosed embexpr.
77
- # With interpolated tokens, tokens.map(&:tok).join will be equal to code.
78
- def self.interpolate_ripper_ignored_tokens(code, tokens)
79
- line_positions = [0]
80
- code.lines.each do |line|
81
- line_positions << line_positions.last + line.bytesize
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
- prev_byte_pos = 0
84
- interpolated = []
85
- prev_line = 1
86
- tokens.each do |t|
87
- line, col = t.pos
88
- byte_pos = line_positions[line - 1] + col
89
- if prev_byte_pos < byte_pos
90
- tok = code.byteslice(prev_byte_pos...byte_pos)
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 << t
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
- def self.ripper_lex_without_warning(code, local_variables: [])
108
- verbose, $VERBOSE = $VERBOSE, nil
109
- lvars_code = generate_local_variables_assign_code(local_variables)
110
- original_code = code
111
- if lvars_code
112
- code = "#{lvars_code}\n#{code}"
113
- line_no = 0
114
- else
115
- line_no = 1
116
- end
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
- compile_with_errors_suppressed(code, line_no: line_no) do |inner_code, line_no|
119
- lexer = Ripper::Lexer.new(inner_code, '-', line_no)
120
- tokens = []
121
- lexer.scan.each do |t|
122
- next if t.pos.first == 0
123
- prev_tk = tokens.last
124
- position_overlapped = prev_tk && t.pos[0] == prev_tk.pos[0] && t.pos[1] < prev_tk.pos[1] + prev_tk.tok.bytesize
125
- if position_overlapped
126
- tokens[-1] = t if ERROR_TOKENS.include?(prev_tk.event) && !ERROR_TOKENS.include?(t.event)
127
- else
128
- tokens << t
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
- interpolate_ripper_ignored_tokens(original_code, tokens)
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: LARGE
1
+ TYPE: ASCII_LARGE
2
2
 
3
- -+smJYYN?mm-
4
- HB"BBYT TQg NggT
5
- 9Q+g Nm,T 8g NJW
6
- YS+ N2NJ"Sg N?
7
- BQg #( gT Nggggk J
8
- 5j NJ NJ NNge
9
- #Q #JJ NgT N(
10
- @j bj mT J
11
- Bj @/d NJ (
12
- #q #(( NgT #J
13
- 5d #(t mT $d
14
- #q @(@J NJB;
15
- @( 5d ? HHH H HQmgggggggmN qD
16
- 5d #uN 2QdH E O
17
- 5 5JSd Nd NJH @d j
18
- Fd @J4d s NQH #d (
19
- #( #o6d Nd NgH #d #d
20
- 4 B&Od v NgT #d F
21
- #( 9JGd NH NgUd F
22
- #d #GJQ d NP $
23
- #J #U+#Q N Q # j
24
- j /W BQ+ BQ d NJ NJ
25
- - NjJH HBIjTQggPJQgW N W k #J
26
- #J b HYWgggN j s Nag d NN b #d
27
- #J 5- D s Ngg N d Nd F
28
- Fd BKH2 #+ s NNgg J Q J ]
29
- F H @ J N y K(d P I
30
- F4 E N? #d y #Q NJ E j
31
- F W Nd q m Bg NxW N(H-
32
- F d b @ m Hd gW vKJ
33
- NJ d K d s Bg aT FDd
34
- b # d N m BQ mV N>
35
- e5 Nd #d NggggggQWH HHHH NJ -
36
- m7 NW H N HSVO1z=?11-
37
- NgTH bB kH WBHWWHBHWmQgg&gggggNNN
38
- NNggggggNN
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
  ⣀⣴⠾⠛⠉⠁ ⠙⣿⣶⣤⣶⣟⣉ ⠈⠻⣦
@@ -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::AbstractSyntaxTree.of(method)&.source rescue nil
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
- context_binding = @irb_context.workspace.binding
129
- eval(code, context_binding)
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
- false
92
+ true
72
93
  end
73
94
 
74
95
  def should_be_handled_by_debugger?
data/lib/irb/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
 
7
7
  module IRB # :nodoc:
8
- VERSION = "1.13.2"
8
+ VERSION = "1.15.2"
9
9
  @RELEASE_VERSION = VERSION
10
- @LAST_UPDATE_DATE = "2024-06-15"
10
+ @LAST_UPDATE_DATE = "2025-04-03"
11
11
  end
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].kind_of?(Binding)
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
- def self.install_helper_methods
180
- HelperMethod.helper_methods.each do |name, helper_method_class|
181
- define_method name do |*args, **opts, &block|
182
- helper_method_class.instance.execute(*args, **opts, &block)
183
- end unless method_defined?(name)
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