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.
- checksums.yaml +4 -4
- data/.rdoc_options +5 -0
- data/CONTRIBUTING.md +52 -0
- data/EXTEND_IRB.md +3 -0
- data/Gemfile +11 -1
- data/README.md +13 -293
- data/doc/COMMAND_LINE_OPTIONS.md +69 -0
- data/doc/COMPARED_WITH_PRY.md +22 -0
- data/doc/Configurations.md +274 -0
- data/doc/EXTEND_IRB.md +122 -0
- data/doc/Index.md +705 -0
- data/doc/irb/irb.rd.ja +1 -1
- data/lib/irb/color.rb +251 -162
- data/lib/irb/color_printer.rb +10 -9
- data/lib/irb/command/base.rb +46 -13
- data/lib/irb/command/copy.rb +83 -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 +7 -4
- data/lib/irb/command/ls.rb +29 -15
- data/lib/irb/completion.rb +81 -57
- data/lib/irb/context.rb +132 -53
- data/lib/irb/debug/ui.rb +2 -4
- data/lib/irb/debug.rb +9 -12
- data/lib/irb/default_commands.rb +19 -8
- data/lib/irb/easter-egg.rb +13 -7
- data/lib/irb/ext/multi-irb.rb +2 -0
- data/lib/irb/history.rb +84 -55
- data/lib/irb/init.rb +7 -2
- data/lib/irb/input-method.rb +167 -130
- data/lib/irb/inspector.rb +42 -36
- data/lib/irb/lc/help-message +2 -2
- data/lib/irb/lc/ja/help-message +4 -4
- data/lib/irb/nesting_parser.rb +364 -213
- data/lib/irb/pager.rb +137 -7
- data/lib/irb/ruby-lex.rb +230 -302
- data/lib/irb/ruby_logo.aa +79 -37
- data/lib/irb/source_finder.rb +15 -22
- data/lib/irb/startup_message.rb +83 -0
- data/lib/irb/statement.rb +21 -0
- data/lib/irb/version.rb +2 -2
- data/lib/irb/workspace.rb +22 -31
- data/lib/irb.rb +148 -986
- data/man/irb.1 +37 -2
- metadata +42 -12
- data/.document +0 -4
- data/Rakefile +0 -54
- data/bin/console +0 -6
- data/bin/setup +0 -6
- data/irb.gemspec +0 -46
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
|
⣀⣴⠾⠛⠉⠁ ⠙⣿⣶⣤⣶⣟⣉ ⠈⠻⣦
|
|
@@ -78,3 +116,7 @@ TYPE: UNICODE
|
|
|
78
116
|
⢻⣾⡇ ⠘⣷ ⣼⠃ ⠘⣷⣠⣴⠟⠋ ⠙⢷⣄⢸⣿
|
|
79
117
|
⠻⣧⡀ ⠘⣧⣰⡏ ⢀⣠⣤⠶⠛⠉⠛⠛⠛⠛⠛⠛⠻⢶⣶⣶⣶⣶⣶⣤⣤⣽⣿⣿
|
|
80
118
|
⠈⠛⠷⢦⣤⣽⣿⣥⣤⣶⣶⡿⠿⠿⠶⠶⠶⠶⠾⠛⠛⠛⠛⠛⠛⠛⠋⠉⠉⠉⠉⠉⠉⠁
|
|
119
|
+
TYPE: UNICODE_SMALL
|
|
120
|
+
⢀⡴⠊⢉⡟⢿
|
|
121
|
+
⣎⣀⣴⡋⡟⣻
|
|
122
|
+
⣟⣼⣱⣽⣟⣾
|
data/lib/irb/source_finder.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
35
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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::
|
|
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 =
|
|
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
|
-
|
|
129
|
-
|
|
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
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
|
|
@@ -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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
|