[ruby-core:95668] [Ruby master Feature#11660] a falsy value (similar to js undefined) that facilitates forwarding of default arguments
From:
daniel@...42.com
Date:
2019-11-04 15:22:01 UTC
List:
ruby-core #95668
Issue #11660 has been updated by Dan0042 (Daniel DeLorme). alanwu (Alan Wu) wrote: > Since the beginning of time (correct me if I'm wrong), the two falsy values in Ruby has been `false` and `nil`, period. > Adding another falsy value is a big change. I Agree. Not saying there's no benefit, but this is too big a change for too small a benefit. Usually `nil` will play the role of the undefined value, so it might be nice if a method definition allowed something like `def foo(v ||= 42)`. But nowadays we have keyword arguments which do exactly what is needed in this case. ```ruby def f2(x: 2) x end def f1(y:1, **kw) y + f2(**kw) end f1(y: 3) #=> 5 ``` ---------------------------------------- Feature #11660: a falsy value (similar to js undefined) that facilitates forwarding of default arguments https://bugs.ruby-lang.org/issues/11660#change-82454 * 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:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>