summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2024-07-01 02:13:22 +0900
committergit <svn-admin@ruby-lang.org>2024-06-30 17:13:27 +0000
commitde2d9c8e22b59ee9be5491c1abe8ab02bee66e84 (patch)
tree4e1093d38f6bf1ccda6c0f11bc3b2db5cb95b410 /lib
parentc4baf3b3c0953c8df24a87db2059f831f45f19ab (diff)
[ruby/irb] Allow assigning and using local variable name conflicting
with command (https://github.com/ruby/irb/pull/961) https://github.com/ruby/irb/commit/00603d470f
Diffstat (limited to 'lib')
-rw-r--r--lib/irb.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index b3435c257e..b417d9c2ec 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -1138,6 +1138,8 @@ module IRB
end
end
+ ASSIGN_OPERATORS_REGEXP = Regexp.union(%w[= += -= *= /= %= **= &= |= &&= ||= ^= <<= >>=])
+
def parse_command(code)
command_name, arg = code.strip.split(/\s+/, 2)
return unless code.lines.size == 1 && command_name
@@ -1149,6 +1151,12 @@ module IRB
return [alias_name, arg]
end
+ # Assignment-like expression is not a command
+ return if arg.start_with?(ASSIGN_OPERATORS_REGEXP) && !arg.start_with?(/==|=~/)
+
+ # Local variable have precedence over command
+ return if @context.local_variables.include?(command)
+
# Check visibility
public_method = !!Kernel.instance_method(:public_method).bind_call(@context.main, command) rescue false
private_method = !public_method && !!Kernel.instance_method(:method).bind_call(@context.main, command) rescue false