[ruby/irb] Drop unused arguments in RubyLex

(https://github.com/ruby/irb/pull/504)

* Simplify `RubyLex#set_prompt`

It's optional argument is never used by any caller.

* Remove the optional `p` argument from `RubyLex#set_input`

The argument is only used in a test case, which can be easily replaced by
a block argument.
This commit is contained in:
Stan Lo 2023-01-11 21:26:12 +00:00 committed by git
parent 3642006872
commit c693dfd7ef
2 changed files with 7 additions and 12 deletions

View File

@ -48,7 +48,7 @@ class RubyLex
end end
# io functions # io functions
def set_input(io, p = nil, context:, &block) def set_input(io, context:, &block)
@io = io @io = io
if @io.respond_to?(:check_termination) if @io.respond_to?(:check_termination)
@io.check_termination do |code| @io.check_termination do |code|
@ -116,22 +116,15 @@ class RubyLex
end end
end end
if p.respond_to?(:call) if block_given?
@input = p
elsif block_given?
@input = block @input = block
else else
@input = Proc.new{@io.gets} @input = Proc.new{@io.gets}
end end
end end
def set_prompt(p = nil, &block) def set_prompt(&block)
p = block if block_given? @prompt = block
if p.respond_to?(:call)
@prompt = p
else
@prompt = Proc.new{print p}
end
end end
ERROR_TOKENS = [ ERROR_TOKENS = [

View File

@ -62,7 +62,9 @@ module TestIRB
context = build_context(local_variables) context = build_context(local_variables)
io = proc{ lines.join("\n") } io = proc{ lines.join("\n") }
ruby_lex.set_input(io, io, context: context) ruby_lex.set_input(io, context: context) do
lines.join("\n")
end
ruby_lex.lex(context) ruby_lex.lex(context)
ruby_lex ruby_lex
end end