[ruby-core:95652] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments

From: fg@...
Date: 2019-11-02 10:06:36 UTC
List: ruby-core #95652
Issue #11660 has been updated by decuplet (Nikita Shilnikov).


For this purpose, I built a [special value](https://github.com/dry-rb/dry-core/blob/99e4035148af729298430aefe85b4c93cb318195/lib/dry/core/constants.rb#L41) a while ago. It has been working fine all this time. I don't think there's a need in adding such special-cased value to the language. It would only slightly improve the experience over a hand-crafted ten-lines-of-code solution. The whole story of passing arguments in Ruby is already complicated enough.

----------------------------------------
Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments
https://bugs.ruby-lang.org/issues/11660#change-82440

* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'll call it "missing" here.  Consider the following scenario:

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = some_expression)
  foo default1
end

def foobar(default1 = some_expression)
  bar default1
end 
```

if you had "missing":

```ruby
def foo(default1 = some_expression)
end

def bar(default1 = missing)
  foo default1
end

def foobar(default1 = missing)
  bar default1
end 
```
missing passed as arg would be ignored (as if it wasn't passed at all)
and you wouldn't have to repeat the default value expression in every method

I believe that's how undefined works in js6 with respect to default args 




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next