summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStan Lo <[email protected]>2025-01-12 20:59:32 +0800
committergit <[email protected]>2025-01-12 12:59:35 +0000
commit450d9dc8bf086747c4dde03441a44873163a2b9c (patch)
treed1b5155d724cc163433fa91a4324427f7418abe7 /lib
parent9f8defe8d2f406b0170a275b5d369957075ea059 (diff)
[ruby/irb] Group private methods together in `IRB::Context`
(https://github.com/ruby/irb/pull/1064) This makes them easier to find and matches the convention of the codebase. https://github.com/ruby/irb/commit/ce8fa6857c
Diffstat (limited to 'lib')
-rw-r--r--lib/irb/context.rb90
1 files changed, 46 insertions, 44 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index 8d6545224d..d87e8451e9 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -155,11 +155,6 @@ module IRB
@command_aliases = IRB.conf[:COMMAND_ALIASES].dup
end
- private def term_interactive?
- return true if ENV['TEST_IRB_FORCE_INTERACTIVE']
- STDIN.tty? && ENV['TERM'] != 'dumb'
- end
-
def use_tracer=(val)
require_relative "ext/tracer" if val
IRB.conf[:USE_TRACER] = val
@@ -177,45 +172,6 @@ module IRB
__send__(__method__, val)
end
- private def build_completor
- completor_type = IRB.conf[:COMPLETOR]
-
- # Gem repl_type_completor is added to bundled gems in Ruby 3.4.
- # Use :type as default completor only in Ruby 3.4 or later.
- verbose = !!completor_type
- completor_type ||= RUBY_VERSION >= '3.4' ? :type : :regexp
-
- case completor_type
- when :regexp
- return RegexpCompletor.new
- when :type
- completor = build_type_completor(verbose: verbose)
- return completor if completor
- else
- warn "Invalid value for IRB.conf[:COMPLETOR]: #{completor_type}"
- end
- # Fallback to RegexpCompletor
- RegexpCompletor.new
- end
-
- private def build_type_completor(verbose:)
- if RUBY_ENGINE == 'truffleruby'
- # Avoid SyntaxError. truffleruby does not support endless method definition yet.
- warn 'TypeCompletor is not supported on TruffleRuby yet' if verbose
- return
- end
-
- begin
- require 'repl_type_completor'
- rescue LoadError => e
- warn "TypeCompletor requires `gem repl_type_completor`: #{e.message}" if verbose
- return
- end
-
- ReplTypeCompletor.preload_rbs
- TypeCompletor.new(self)
- end
-
def save_history=(val)
IRB.conf[:SAVE_HISTORY] = val
end
@@ -739,5 +695,51 @@ module IRB
main_object = main
Object === main_object ? main_object.__send__(method_name) : Object.instance_method(method_name).bind_call(main_object)
end
+
+ private
+
+ def term_interactive?
+ return true if ENV['TEST_IRB_FORCE_INTERACTIVE']
+ STDIN.tty? && ENV['TERM'] != 'dumb'
+ end
+
+ def build_completor
+ completor_type = IRB.conf[:COMPLETOR]
+
+ # Gem repl_type_completor is added to bundled gems in Ruby 3.4.
+ # Use :type as default completor only in Ruby 3.4 or later.
+ verbose = !!completor_type
+ completor_type ||= RUBY_VERSION >= '3.4' ? :type : :regexp
+
+ case completor_type
+ when :regexp
+ return RegexpCompletor.new
+ when :type
+ completor = build_type_completor(verbose: verbose)
+ return completor if completor
+ else
+ warn "Invalid value for IRB.conf[:COMPLETOR]: #{completor_type}"
+ end
+ # Fallback to RegexpCompletor
+ RegexpCompletor.new
+ end
+
+ def build_type_completor(verbose:)
+ if RUBY_ENGINE == 'truffleruby'
+ # Avoid SyntaxError. truffleruby does not support endless method definition yet.
+ warn 'TypeCompletor is not supported on TruffleRuby yet' if verbose
+ return
+ end
+
+ begin
+ require 'repl_type_completor'
+ rescue LoadError => e
+ warn "TypeCompletor requires `gem repl_type_completor`: #{e.message}" if verbose
+ return
+ end
+
+ ReplTypeCompletor.preload_rbs
+ TypeCompletor.new(self)
+ end
end
end