Festlegen eines Standardwert für ein Splat Argument gibt einen Fehler einen Standardwert gesetzt:Wie für ein Splat Argument in Ruby
1.9.3-p374 :001 > def a b, *c = nil
1.9.3-p374 :002?> end
SyntaxError: (irb):1: syntax error, unexpected '=', expecting ';' or '\n'
def a b, *c = nil
^
from /Users/me/.rvm/rubies/ruby-1.9.3-p374/bin/irb:16:in `<main>'
Einige Variationen Ich habe versucht, das auch nicht funktionieren:
1.9.3-p374 :003 > def a b, *c = []
1.9.3-p374 :005 > def a b, (*c) = nil
1.9.3-p374 :007 > def a b, (*c = [])
1.9.3-p374 :009 > def a b, (*c = [1,2,3])
1.9.3-p374 :011 > def a b, *c = [1,2,3]
Ich sehe hier kein Unbestimmtheits-Problem, also scheint es möglich zu sein.
Verwandte: Why non-explicit splat param plus default param is wrong syntax for method definition in Ruby 1.9?
Splat Argument ist standardmäßig leer Array – fl00r
Ja, aber was ist mit einem Standardargument? – jordanpg
Gibt es einen Grund, warum Sie eine Antwort noch nicht akzeptiert haben? – vlasits