Keyword arguments with symbol as default value
RRRoy BBBean <[email protected]>
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <[email protected]> |
I need to use a Ruby symbol as the default value for an argument, but I also want to use keyword arguments, because they are so neat. I found that wrapping the symbol in in parenthesis or using a constant to refer to the symbol works. Is there a better way to do this with Ruby 2.6+ (and still have a symbol as the default value)? def mymethod myarg:(:mydefaultsymbol) p myarg end # or DEFAULT_MYVALUE = :mydefaultsymbol def mymethod myarg:DEFAULT_MYVALUE p myarg end # where, in either case, mymethod # outputs :mydefaultsymbol Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>