[ruby-core:74262] [Ruby trunk Feature#12157] Is the option hash necessary for future Rubys?

From: sawadatsuyoshi@...
Date: 2016-03-10 07:43:11 UTC
List: ruby-core #74262
Issue #12157 has been updated by Tsuyoshi Sawada.


Colin Fulton wrote:
> A special syntax to distinguish keyword arguments from options hashes could be an interesting solution, but I am not sure how that could be done well.

Perhaps a semicolon would work:

~~~RUBY
foo("a", "b", c: 1; c: 2, d: 3) # => arguments `"a"`, `"b"`, and `{:c => 1}`; keyword arguments `c` with default `2` and `d` with `3`.
~~~
This has advantage that the same name can appear simultaneously in the final-argument hash and keyword argument (i.e., `:c`).

----------------------------------------
Feature #12157: Is the option hash necessary for future Rubys?
https://bugs.ruby-lang.org/issues/12157#change-57394

* Author: Colin Fulton
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Option hashes were great before Ruby had named arguments, but with the addition of named arguments and the double splat operator are they still needed?

One can convert named arguments into an option hash by using the double splat operator in the parameter list, so option hashes are redundant. More importantly, the existence of both option hashes and named arguments is creating odd or ugly edge cases. See #12022, #10708, and #11860. Legacy software can mostly be updated using a double splatted parameter, so it shouldn't be a hard shift to make.

What do you all think?

_Apologies if this discussion has happened before. I searched for a bit but couldn't turn anything up._



-- 
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>

In This Thread

Prev Next