In Ruby, a common design pattern involves creating a method that serves as both a getter and a setter. For example, a method might update a setting if a value is passed to it, or return the current setting if no value is provided. However, using a standard default argument like `value = nil` creates a logic conflict: the code cannot distinguish between a user intentionally passing `nil` to clear a setting and a user passing nothing to read the current setting. While both result in `value` being `nil`, they represent different intents in the method's contract.

The article discusses a specific Ruby programming technique, and Chris Zempel is the primary author/source of this technical insight.
To solve this, developers often resort to creating a unique constant, such as `NOT_PROVIDED = Object.new.freeze`, and checking if the input equals that specific object. While effective, this approach introduces extra boilerplate and requires managing additional constants. A more concise technique involves leveraging how Ruby evaluates default arguments. By defining a method with a default argument that includes an assignment—such as `def cloaking(value = (nothing_provided = true))`—the developer can create a local flag that only triggers when the argument is omitted.
This mechanism works because Ruby only evaluates the default argument expression when a caller provides no input. In that scenario, `nothing_provided` is set to `true`, and `value` becomes `true`. If the caller provides any argument, even `nil` or `false`, Ruby skips the default expression entirely. In these cases, the local variable `nothing_provided` still exists but remains `nil` because the assignment never executed. This allows the method to branch logic based on whether the argument was truly missing. This pattern is notably used in the Rails framework's `index_with` method to handle optional defaults and block logic.
Despite its utility, the technique is a specialized approach that some developers argue is less clean than using standard Ruby setter syntax. While the assignment-in-default-argument trick provides a clever way to handle dual-purpose methods, it relies on a specific behavior of the Ruby interpreter that may be less intuitive than explicit method overloading. For many use cases, standard Ruby conventions—such as defining separate methods for getting and setting values—remain the preferred way to maintain clear, readable code.