irb 1.14.3 → 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 (48) 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 -310
  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 +35 -0
  16. data/lib/irb/command/copy.rb +83 -0
  17. data/lib/irb/command/history.rb +1 -1
  18. data/lib/irb/command/internal_helpers.rb +6 -3
  19. data/lib/irb/command/ls.rb +6 -4
  20. data/lib/irb/completion.rb +69 -52
  21. data/lib/irb/context.rb +100 -64
  22. data/lib/irb/debug.rb +3 -3
  23. data/lib/irb/default_commands.rb +4 -1
  24. data/lib/irb/easter-egg.rb +3 -1
  25. data/lib/irb/ext/multi-irb.rb +2 -0
  26. data/lib/irb/history.rb +4 -0
  27. data/lib/irb/init.rb +6 -1
  28. data/lib/irb/input-method.rb +158 -122
  29. data/lib/irb/inspector.rb +12 -7
  30. data/lib/irb/lc/help-message +2 -2
  31. data/lib/irb/lc/ja/help-message +1 -1
  32. data/lib/irb/nesting_parser.rb +362 -213
  33. data/lib/irb/pager.rb +127 -6
  34. data/lib/irb/ruby-lex.rb +225 -299
  35. data/lib/irb/ruby_logo.aa +4 -0
  36. data/lib/irb/source_finder.rb +12 -18
  37. data/lib/irb/startup_message.rb +83 -0
  38. data/lib/irb/statement.rb +21 -0
  39. data/lib/irb/version.rb +2 -2
  40. data/lib/irb/workspace.rb +9 -0
  41. data/lib/irb.rb +112 -927
  42. data/man/irb.1 +2 -0
  43. metadata +42 -12
  44. data/.document +0 -8
  45. data/Rakefile +0 -52
  46. data/bin/console +0 -6
  47. data/bin/setup +0 -6
  48. data/irb.gemspec +0 -46
data/lib/irb/ruby_logo.aa CHANGED
@@ -116,3 +116,7 @@ TYPE: UNICODE
116
116
  ⢻⣾⡇ ⠘⣷ ⣼⠃ ⠘⣷⣠⣴⠟⠋ ⠙⢷⣄⢸⣿
117
117
  ⠻⣧⡀ ⠘⣧⣰⡏ ⢀⣠⣤⠶⠛⠉⠛⠛⠛⠛⠛⠛⠻⢶⣶⣶⣶⣶⣶⣤⣤⣽⣿⣿
118
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
@@ -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
@@ -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.3"
8
+ VERSION = "1.18.0"
9
9
  @RELEASE_VERSION = VERSION
10
- @LAST_UPDATE_DATE = "2024-12-18"
10
+ @LAST_UPDATE_DATE = "2026-04-21"
11
11
  end
data/lib/irb/workspace.rb CHANGED
@@ -55,6 +55,15 @@ EOF
55
55
  # Note that this will typically be IRB::TOPLEVEL_BINDING
56
56
  # This is to avoid RubyGems' local variables (see issue #17623)
57
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')
58
67
  end
59
68
  end
60
69