Issue #17785 has been updated by nobu (Nobuyoshi Nakada).


duerst (Martin D=FCrst) wrote in #note-7:
> What about finding something in between the two? E.g. even just introduci=
ng `variable_get` as an alias to `binding.local_variable_get` would make th=
is easier to use. And if this really needs optimization, it could be done, =
too, but using a different argument name would solve the problem.

In built-in methods written in Ruby, we chose `__builtin.arg!(:in)` form (s=
ee timve.rb).

> With respect to `\`, it reminds me of older languages (such as m4, C, and=
 TeX) where there's a purely string-based level below (or before) the usual=
 structured syntax. Do we want Ruby to descend to that level? Escaping exis=
ts inside strings because you don't want the range of data you can handle w=
ith a programming language to be restricted by the syntax of the language i=
tself. Also, escaping inside strings is frequent enough for everybody, and =
occurs in a very similar form across a wide range of programming languages,=
 so that every programmer knows it. Backslashes in front of keywords would =
be a whole different matter.

Agree, and backslashes will be troublesome in `eval` obviously.

----------------------------------------
Feature #17785: Allow named parameters to be keywords
https://bugs.ruby-lang.org/issues/17785#change-91453

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
We should allow named parameters to be keywords and use add a trailing `_` =
to the corresponding variable:

```ruby
def check(arg, class:)
  arg.is_a?(class_)
end

check(42, class: Integer) # =3D> true
```

Currently, if we want such an API we have to use `**rest`:

```ruby
def check(arg, **rest)
  class_ =3D rest.fetch(:class) { raise ArgumentError('missing keyword: :cl=
ass')}
  if rest.size > 1
    unknown =3D rest.keys - [:class]
    raise ArgumentError("unknown keyword(s): :#{unknown.join(', :')})
  end

  arg.is_a?(class_)
end
```

This is very verbose, much less convenient, much less readable, prevents `s=
teep` from generating the proper signature, etc.

We should do the same for pattern match.



-- =

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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>