Skip to content

Commit 450d9dc

Browse files
st0012matzbot
authored andcommitted
[ruby/irb] Group private methods together in IRB::Context
(ruby/irb#1064) This makes them easier to find and matches the convention of the codebase. ruby/irb@ce8fa6857c
1 parent 9f8defe commit 450d9dc

File tree

1 file changed

+46
-44
lines changed

1 file changed

+46
-44
lines changed

lib/irb/context.rb

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,6 @@ def initialize(irb, workspace = nil, input_method = nil)
155155
@command_aliases = IRB.conf[:COMMAND_ALIASES].dup
156156
end
157157

158-
private def term_interactive?
159-
return true if ENV['TEST_IRB_FORCE_INTERACTIVE']
160-
STDIN.tty? && ENV['TERM'] != 'dumb'
161-
end
162-
163158
def use_tracer=(val)
164159
require_relative "ext/tracer" if val
165160
IRB.conf[:USE_TRACER] = val
@@ -177,45 +172,6 @@ def use_loader=(val)
177172
__send__(__method__, val)
178173
end
179174

180-
private def build_completor
181-
completor_type = IRB.conf[:COMPLETOR]
182-
183-
# Gem repl_type_completor is added to bundled gems in Ruby 3.4.
184-
# Use :type as default completor only in Ruby 3.4 or later.
185-
verbose = !!completor_type
186-
completor_type ||= RUBY_VERSION >= '3.4' ? :type : :regexp
187-
188-
case completor_type
189-
when :regexp
190-
return RegexpCompletor.new
191-
when :type
192-
completor = build_type_completor(verbose: verbose)
193-
return completor if completor
194-
else
195-
warn "Invalid value for IRB.conf[:COMPLETOR]: #{completor_type}"
196-
end
197-
# Fallback to RegexpCompletor
198-
RegexpCompletor.new
199-
end
200-
201-
private def build_type_completor(verbose:)
202-
if RUBY_ENGINE == 'truffleruby'
203-
# Avoid SyntaxError. truffleruby does not support endless method definition yet.
204-
warn 'TypeCompletor is not supported on TruffleRuby yet' if verbose
205-
return
206-
end
207-
208-
begin
209-
require 'repl_type_completor'
210-
rescue LoadError => e
211-
warn "TypeCompletor requires `gem repl_type_completor`: #{e.message}" if verbose
212-
return
213-
end
214-
215-
ReplTypeCompletor.preload_rbs
216-
TypeCompletor.new(self)
217-
end
218-
219175
def save_history=(val)
220176
IRB.conf[:SAVE_HISTORY] = val
221177
end
@@ -739,5 +695,51 @@ def safe_method_call_on_main(method_name)
739695
main_object = main
740696
Object === main_object ? main_object.__send__(method_name) : Object.instance_method(method_name).bind_call(main_object)
741697
end
698+
699+
private
700+
701+
def term_interactive?
702+
return true if ENV['TEST_IRB_FORCE_INTERACTIVE']
703+
STDIN.tty? && ENV['TERM'] != 'dumb'
704+
end
705+
706+
def build_completor
707+
completor_type = IRB.conf[:COMPLETOR]
708+
709+
# Gem repl_type_completor is added to bundled gems in Ruby 3.4.
710+
# Use :type as default completor only in Ruby 3.4 or later.
711+
verbose = !!completor_type
712+
completor_type ||= RUBY_VERSION >= '3.4' ? :type : :regexp
713+
714+
case completor_type
715+
when :regexp
716+
return RegexpCompletor.new
717+
when :type
718+
completor = build_type_completor(verbose: verbose)
719+
return completor if completor
720+
else
721+
warn "Invalid value for IRB.conf[:COMPLETOR]: #{completor_type}"
722+
end
723+
# Fallback to RegexpCompletor
724+
RegexpCompletor.new
725+
end
726+
727+
def build_type_completor(verbose:)
728+
if RUBY_ENGINE == 'truffleruby'
729+
# Avoid SyntaxError. truffleruby does not support endless method definition yet.
730+
warn 'TypeCompletor is not supported on TruffleRuby yet' if verbose
731+
return
732+
end
733+
734+
begin
735+
require 'repl_type_completor'
736+
rescue LoadError => e
737+
warn "TypeCompletor requires `gem repl_type_completor`: #{e.message}" if verbose
738+
return
739+
end
740+
741+
ReplTypeCompletor.preload_rbs
742+
TypeCompletor.new(self)
743+
end
742744
end
743745
end

0 commit comments

Comments
 (0)