Skip to content

Commit

Permalink
Drop unused arguments in RubyLex (#504)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
st0012 authored Jan 11, 2023
1 parent 463b86d commit 59bf237
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 4 additions & 11 deletions lib/irb/ruby-lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def self.compile_with_errors_suppressed(code, line_no: 1)
end

# io functions
def set_input(io, p = nil, context:, &block)
def set_input(io, context:, &block)
@io = io
if @io.respond_to?(:check_termination)
@io.check_termination do |code|
Expand Down Expand Up @@ -116,22 +116,15 @@ def set_input(io, p = nil, context:, &block)
end
end

if p.respond_to?(:call)
@input = p
elsif block_given?
if block_given?
@input = block
else
@input = Proc.new{@io.gets}
end
end

def set_prompt(p = nil, &block)
p = block if block_given?
if p.respond_to?(:call)
@prompt = p
else
@prompt = Proc.new{print p}
end
def set_prompt(&block)
@prompt = block
end

ERROR_TOKENS = [
Expand Down
4 changes: 3 additions & 1 deletion test/irb/test_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def ruby_lex_for_lines(lines, local_variables: [])

context = build_context(local_variables)
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
end
Expand Down

0 comments on commit 59bf237

Please sign in to comment.