From 4cf9f171b9dc241e1b010c0c1f02f369be1f4f31 Mon Sep 17 00:00:00 2001 From: tompng Date: Sat, 15 Nov 2025 13:57:30 +0900 Subject: [PATCH] Avoid creating method objects unnecessarily when distinguishing between commands and statements. --- lib/irb/context.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/irb/context.rb b/lib/irb/context.rb index 395d9081f..4e21220dd 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -632,14 +632,15 @@ def parse_input(code, is_assignment_expression) command_class = Command.load_command(command) end - # Check visibility - public_method = !!KERNEL_PUBLIC_METHOD.bind_call(main, command) rescue false - private_method = !public_method && !!KERNEL_METHOD.bind_call(main, command) rescue false - if command_class && Command.execute_as_command?(command, public_method: public_method, private_method: private_method) - Statement::Command.new(code, command_class, arg) - else - Statement::Expression.new(code, is_assignment_expression) + if command_class + # Check whether the command conflicts with existing methods + public_method = !!KERNEL_PUBLIC_METHOD.bind_call(main, command) rescue false + private_method = !public_method && !!KERNEL_METHOD.bind_call(main, command) rescue false + if Command.execute_as_command?(command, public_method: public_method, private_method: private_method) + return Statement::Command.new(code, command_class, arg) + end end + Statement::Expression.new(code, is_assignment_expression) end def colorize_input(input, complete:)