[ruby-core:94521] [Ruby master Feature#16123] Allow calling a private method with `self.`
From:
sawadatsuyoshi@...
Date:
2019-08-24 02:54:23 UTC
List:
ruby-core #94521
Issue #16123 has been updated by sawa (Tsuyoshi Sawada). The code you presented does not set the attribute methods private. The `attr_accessor` returns `nil`. Your `private` is applied to nothng. ---------------------------------------- Feature #16123: Allow calling a private method with `self.` https://bugs.ruby-lang.org/issues/16123#change-80962 * Author: dylants (Dylan Thacker-Smith) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- ## Problem There is an inconsistency between calling a private attribute writer being allowed with `self.value =` syntax and `self.value` not being allowed on a private attribute writer. Calling a private method in this way can be useful when trying to assign the return value of this private method to a local variable with the same name. ## Solution The attached patch handles this by compiling the calling into a function call by using the `VM_CALL_FCALL` flag, so it is as if the call were made without the `self.` prefix, except it won't be confused with local variables at the VM instruction level. It is also compiled like an assignment call, except I didn't use the `COMPILE_RECV` macro, since that would remove the `CHECK` macro usage around the `COMPILE` line. ---Files-------------------------------- 0001-Allow-calling-a-private-method-with-self.diff.txt (3.28 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>