Skip to content

Commit 59bf237

Browse files
authored
Drop unused arguments in RubyLex (#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.
1 parent 463b86d commit 59bf237

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

lib/irb/ruby-lex.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def self.compile_with_errors_suppressed(code, line_no: 1)
4848
end
4949

5050
# io functions
51-
def set_input(io, p = nil, context:, &block)
51+
def set_input(io, context:, &block)
5252
@io = io
5353
if @io.respond_to?(:check_termination)
5454
@io.check_termination do |code|
@@ -116,22 +116,15 @@ def set_input(io, p = nil, context:, &block)
116116
end
117117
end
118118

119-
if p.respond_to?(:call)
120-
@input = p
121-
elsif block_given?
119+
if block_given?
122120
@input = block
123121
else
124122
@input = Proc.new{@io.gets}
125123
end
126124
end
127125

128-
def set_prompt(p = nil, &block)
129-
p = block if block_given?
130-
if p.respond_to?(:call)
131-
@prompt = p
132-
else
133-
@prompt = Proc.new{print p}
134-
end
126+
def set_prompt(&block)
127+
@prompt = block
135128
end
136129

137130
ERROR_TOKENS = [

test/irb/test_ruby_lex.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def ruby_lex_for_lines(lines, local_variables: [])
6262

6363
context = build_context(local_variables)
6464
io = proc{ lines.join("\n") }
65-
ruby_lex.set_input(io, io, context: context)
65+
ruby_lex.set_input(io, context: context) do
66+
lines.join("\n")
67+
end
6668
ruby_lex.lex(context)
6769
ruby_lex
6870
end

0 commit comments

Comments
 (0)