summaryrefslogtreecommitdiff
path: root/lib/irb/ruby-lex.rb
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2022-11-03 16:32:10 +0000
committergit <svn-admin@ruby-lang.org>2022-11-03 16:32:22 +0000
commitc5d6a483f5f771aa904ea85dad35a368ddf8047a (patch)
treedb87ec96f59ce622276fb73931351a44d7b5bb46 /lib/irb/ruby-lex.rb
parent68ef97d788cf8bff42d981bda41cd26128220740 (diff)
[ruby/irb] Refactor RubyLex and its tests
(https://github.com/ruby/irb/pull/427) * Make sure `RubyLex#set_input`'s context is always present in tests In real-world scenarios, the context should always be non-nil: https://github.com/ruby/irb/blob/master/lib/irb.rb#L489 So we should make sure our test setup reflects that. * Make context a required keyword Since in practice, `set_input`'s context should always be non-nil, its parameters should reflect that. And since `RubyLex#check_state` is only called by `#lex` and `#set_input`, both of which now always require context, we can assume its context should be non-nil too. https://github.com/ruby/irb/commit/1aeeb86203
Diffstat (limited to 'lib/irb/ruby-lex.rb')
-rw-r--r--lib/irb/ruby-lex.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index 54ea2a9e7b..544392228e 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -48,7 +48,7 @@ class RubyLex
end
# io functions
- def set_input(io, p = nil, context: nil, &block)
+ def set_input(io, p = nil, context:, &block)
@io = io
if @io.respond_to?(:check_termination)
@io.check_termination do |code|
@@ -216,7 +216,7 @@ class RubyLex
ltype = process_literal_type(tokens)
indent = process_nesting_level(tokens)
continue = process_continue(tokens)
- lvars_code = self.class.generate_local_variables_assign_code(context&.local_variables || [])
+ lvars_code = self.class.generate_local_variables_assign_code(context.local_variables)
code = "#{lvars_code}\n#{code}" if lvars_code
code_block_open = check_code_block(code, tokens)
[ltype, indent, continue, code_block_open]