irb 1.14.0 → 1.18.0

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rdoc_options +5 -0
  3. data/CONTRIBUTING.md +52 -0
  4. data/EXTEND_IRB.md +3 -0
  5. data/Gemfile +11 -1
  6. data/README.md +13 -293
  7. data/doc/COMMAND_LINE_OPTIONS.md +69 -0
  8. data/doc/COMPARED_WITH_PRY.md +22 -0
  9. data/doc/Configurations.md +274 -0
  10. data/doc/EXTEND_IRB.md +122 -0
  11. data/doc/Index.md +705 -0
  12. data/doc/irb/irb.rd.ja +1 -1
  13. data/lib/irb/color.rb +251 -162
  14. data/lib/irb/color_printer.rb +10 -9
  15. data/lib/irb/command/base.rb +46 -13
  16. data/lib/irb/command/copy.rb +83 -0
  17. data/lib/irb/command/debug.rb +8 -6
  18. data/lib/irb/command/help.rb +1 -1
  19. data/lib/irb/command/history.rb +1 -1
  20. data/lib/irb/command/internal_helpers.rb +7 -4
  21. data/lib/irb/command/ls.rb +29 -15
  22. data/lib/irb/completion.rb +81 -57
  23. data/lib/irb/context.rb +132 -53
  24. data/lib/irb/debug/ui.rb +2 -4
  25. data/lib/irb/debug.rb +9 -12
  26. data/lib/irb/default_commands.rb +19 -8
  27. data/lib/irb/easter-egg.rb +13 -7
  28. data/lib/irb/ext/multi-irb.rb +2 -0
  29. data/lib/irb/history.rb +84 -55
  30. data/lib/irb/init.rb +7 -2
  31. data/lib/irb/input-method.rb +167 -130
  32. data/lib/irb/inspector.rb +42 -36
  33. data/lib/irb/lc/help-message +2 -2
  34. data/lib/irb/lc/ja/help-message +4 -4
  35. data/lib/irb/nesting_parser.rb +364 -213
  36. data/lib/irb/pager.rb +137 -7
  37. data/lib/irb/ruby-lex.rb +230 -302
  38. data/lib/irb/ruby_logo.aa +79 -37
  39. data/lib/irb/source_finder.rb +15 -22
  40. data/lib/irb/startup_message.rb +83 -0
  41. data/lib/irb/statement.rb +21 -0
  42. data/lib/irb/version.rb +2 -2
  43. data/lib/irb/workspace.rb +22 -31
  44. data/lib/irb.rb +148 -986
  45. data/man/irb.1 +37 -2
  46. metadata +42 -12
  47. data/.document +0 -4
  48. data/Rakefile +0 -54
  49. data/bin/console +0 -6
  50. data/bin/setup +0 -6
  51. data/irb.gemspec +0 -46
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
  ⣀⣴⠾⠛⠉⠁ ⠙⣿⣶⣤⣶⣟⣉ ⠈⠻⣦
@@ -78,3 +116,7 @@ TYPE: UNICODE
78
116
  ⢻⣾⡇ ⠘⣷ ⣼⠃ ⠘⣷⣠⣴⠟⠋ ⠙⢷⣄⢸⣿
79
117
  ⠻⣧⡀ ⠘⣧⣰⡏ ⢀⣠⣤⠶⠛⠉⠛⠛⠛⠛⠛⠛⠻⢶⣶⣶⣶⣶⣶⣤⣤⣽⣿⣿
80
118
  ⠈⠛⠷⢦⣤⣽⣿⣥⣤⣶⣶⡿⠿⠿⠶⠶⠶⠶⠾⠛⠛⠛⠛⠛⠛⠛⠋⠉⠉⠉⠉⠉⠉⠁
119
+ TYPE: UNICODE_SMALL
120
+ ⢀⡴⠊⢉⡟⢿
121
+ ⣎⣀⣴⡋⡟⣻
122
+ ⣟⣼⣱⣽⣟⣾
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "ruby-lex"
3
+ require 'prism'
4
4
 
5
5
  module IRB
6
6
  class SourceFinder
@@ -29,10 +29,13 @@ module IRB
29
29
 
30
30
  def colorized_content
31
31
  if !binary_file? && file_exist?
32
- end_line = find_end
33
32
  # To correctly colorize, we need to colorize full content and extract the relevant lines.
34
- colored = IRB::Color.colorize_code(file_content)
35
- colored.lines[@line - 1...end_line].join
33
+ colored_lines = IRB::Color.colorize_code(file_content).lines
34
+
35
+ # Handle wrong line number case: line_no passed to eval is wrong, file is edited after load, etc
36
+ return if colored_lines.size < @line
37
+
38
+ colored_lines[@line - 1...find_end].join
36
39
  elsif @ast_source
37
40
  IRB::Color.colorize_code(@ast_source)
38
41
  end
@@ -41,21 +44,12 @@ module IRB
41
44
  private
42
45
 
43
46
  def find_end
44
- lex = RubyLex.new
45
47
  code = file_content
46
48
  lines = code.lines[(@line - 1)..-1]
47
- tokens = RubyLex.ripper_lex_without_warning(lines.join)
48
- prev_tokens = []
49
-
50
- # chunk with line number
51
- tokens.chunk { |tok| tok.pos[0] }.each do |lnum, chunk|
52
- code = lines[0..lnum].join
53
- prev_tokens.concat chunk
54
- continue = lex.should_continue?(prev_tokens)
55
- syntax = lex.check_code_syntax(code, local_variables: [])
56
- if !continue && syntax == :valid
57
- return @line + lnum
58
- end
49
+
50
+ lines.each_with_index do |line, index|
51
+ sub_code = lines.take(index + 1).join
52
+ return @line + index if Prism.parse_success?(sub_code)
59
53
  end
60
54
  @line
61
55
  end
@@ -100,7 +94,7 @@ module IRB
100
94
  Source.new(file, line)
101
95
  elsif method
102
96
  # Method defined with eval, probably in IRB session
103
- source = RubyVM::AbstractSyntaxTree.of(method)&.source rescue nil
97
+ source = RubyVM::InstructionSequence.of(method)&.script_lines&.join rescue nil
104
98
  Source.new(file, line, source)
105
99
  end
106
100
  rescue EvaluationError
@@ -114,7 +108,7 @@ module IRB
114
108
  when "owner"
115
109
  target_method = owner_receiver.instance_method(method)
116
110
  when "receiver"
117
- target_method = owner_receiver.method(method)
111
+ target_method = Kernel.instance_method(:method).bind_call(owner_receiver, method)
118
112
  end
119
113
  super_level.times do |s|
120
114
  target_method = target_method.super_method if target_method
@@ -125,9 +119,8 @@ module IRB
125
119
  end
126
120
 
127
121
  def eval_receiver_or_owner(code)
128
- context_binding = @irb_context.workspace.binding
129
- eval(code, context_binding)
130
- rescue NameError
122
+ @irb_context.workspace.binding.eval(code)
123
+ rescue Exception
131
124
  raise EvaluationError
132
125
  end
133
126
 
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "color"
4
+ require_relative "version"
5
+
6
+ module IRB
7
+ module StartupMessage
8
+ TIPS = [
9
+ 'Type "help" for commands, "help <cmd>" for details',
10
+ '"show_doc method" to view documentation',
11
+ '"ls [object]" to see methods and properties',
12
+ '"ls [object] -g pattern" to filter methods and properties',
13
+ '"edit method" to open the method\'s source in editor',
14
+ '"cd object" to navigate into an object',
15
+ '"show_source method" to view source code',
16
+ '"copy expr" to copy the output to clipboard',
17
+ '"debug" to start integration with the "debug" gem',
18
+ '"history -g pattern" to search history',
19
+ ].freeze
20
+
21
+ class << self
22
+ def display
23
+ logo_lines = load_logo
24
+ info_lines = build_info_lines
25
+
26
+ output = if logo_lines
27
+ combine_logo_and_info(logo_lines, info_lines)
28
+ else
29
+ info_lines.join("\n")
30
+ end
31
+
32
+ # Add a blank line to not immediately touch warning messages
33
+ puts
34
+ puts output
35
+ puts
36
+ end
37
+
38
+ private
39
+
40
+ def load_logo
41
+ encoding = STDOUT.external_encoding || Encoding.default_external
42
+ return nil unless encoding == Encoding::UTF_8
43
+
44
+ logo = IRB.send(:easter_egg_logo, :unicode_small)
45
+ return nil unless logo
46
+
47
+ logo.chomp.lines.map(&:chomp)
48
+ end
49
+
50
+ def build_info_lines
51
+ version_line = "#{Color.colorize('IRB', [:BOLD])} v#{VERSION} - Ruby #{RUBY_VERSION}"
52
+ tip_line = colorize_tip(TIPS.sample)
53
+ dir_line = Color.colorize(short_pwd, [:CYAN])
54
+
55
+ [version_line, tip_line, dir_line]
56
+ end
57
+
58
+ def colorize_tip(tip)
59
+ tip.gsub(/"[^"]*"/) { |match| Color.colorize(match, [:YELLOW]) }
60
+ end
61
+
62
+ def combine_logo_and_info(logo_lines, info_lines)
63
+ max_lines = [logo_lines.size, info_lines.size].max
64
+ lines = max_lines.times.map do |i|
65
+ logo_part = logo_lines[i] || ""
66
+ info_part = info_lines[i] || ""
67
+ colored_logo = Color.colorize(logo_part, [:RED, :BOLD])
68
+ "#{colored_logo} #{info_part}"
69
+ end
70
+ lines.join("\n")
71
+ end
72
+
73
+ def short_pwd
74
+ dir = Dir.pwd
75
+ home = ENV['HOME']
76
+ if home && (dir == home || dir.start_with?("#{home}/"))
77
+ dir = "~#{dir[home.size..]}"
78
+ end
79
+ dir
80
+ end
81
+ end
82
+ end
83
+ end
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
 
data/lib/irb/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
 
7
7
  module IRB # :nodoc:
8
- VERSION = "1.14.0"
8
+ VERSION = "1.18.0"
9
9
  @RELEASE_VERSION = VERSION
10
- @LAST_UPDATE_DATE = "2024-07-06"
10
+ @LAST_UPDATE_DATE = "2026-04-21"
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
@@ -57,6 +55,15 @@ EOF
57
55
  # Note that this will typically be IRB::TOPLEVEL_BINDING
58
56
  # This is to avoid RubyGems' local variables (see issue #17623)
59
57
  @binding = TOPLEVEL_BINDING.dup
58
+
59
+ when 5 # binding in Ruby::Box
60
+ unless defined?(Ruby::Box)
61
+ puts 'Context-mode 5 (binding in Ruby::Box) requires Ruby 4.0 or later.'
62
+ raise NameError, 'Ruby::Box not defined'
63
+ end
64
+
65
+ puts 'Context-mode 5 (binding in Ruby::Box) is experimental. It may be removed or changed without notice.'
66
+ @binding = Ruby::Box.new.eval('Kernel.binding')
60
67
  end
61
68
  end
62
69
 
@@ -70,37 +77,16 @@ EOF
70
77
  unless main.empty?
71
78
  case @main
72
79
  when Module
73
- @binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
80
+ @binding = eval("::IRB.conf[:__MAIN__].module_eval('::Kernel.binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
74
81
  else
75
82
  begin
76
- @binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
83
+ @binding = eval("::IRB.conf[:__MAIN__].instance_eval('::Kernel.binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
77
84
  rescue TypeError
78
85
  fail CantChangeBinding, @main.inspect
79
86
  end
80
87
  end
81
88
  end
82
89
 
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
90
  @binding.local_variable_set(:_, nil)
105
91
  end
106
92
 
@@ -111,6 +97,9 @@ EOF
111
97
  attr_reader :main
112
98
 
113
99
  def load_helper_methods_to_main
100
+ # Do not load helper methods to frozen objects and BasicObject
101
+ return unless Object === @main && !@main.frozen?
102
+
114
103
  ancestors = class<<main;ancestors;end
115
104
  main.extend ExtendCommandBundle if !ancestors.include?(ExtendCommandBundle)
116
105
  main.extend HelpersContainer if !ancestors.include?(HelpersContainer)
@@ -176,11 +165,13 @@ EOF
176
165
  end
177
166
 
178
167
  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)
168
+ class << self
169
+ def install_helper_methods
170
+ HelperMethod.helper_methods.each do |name, helper_method_class|
171
+ define_method name do |*args, **opts, &block|
172
+ helper_method_class.instance.execute(*args, **opts, &block)
173
+ end unless method_defined?(name)
174
+ end
184
175
  end
185
176
  end
186
177