[ruby-core:96004] [Ruby master Feature#16364] Top-level ruby2_keywords

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-82840.20191128041436.ab0a6317de79789d@ruby-lang.org>
Issue #16364 has been updated by matz (Yukihiro Matsumoto).


Accepted.

Matz.


----------------------------------------
Feature #16364: Top-level ruby2_keywords
https://bugs.ruby-lang.org/issues/16364#change-82840

* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
How about defining top-level ruby2_keywords?

```
#!/usr/bin/env ruby

def foo(**kw)
  kw
end

ruby2_keywords def bar(*a)
  foo(*a)
end

bar(k:1) #=> {:k=>1} with no warnings in 2.7
```

Currently, `Module#ruby2_keywords` is defined only in `Module` class.  So, to mark a top-level method as `ruby2_keywords`, we need to workaround by surrounding the definition with `class Object; ruby2_keywords ...; end`.  It is a bit annoying.

I know that practical applications tend to define no top-level methods.  However, I think of two reasons that we want top-level `ruby2_keywords`:

1. To learn `ruby2_keywords`, we tend to write a minimal script without class definition.  Actually, I saw some people (even a committer) confused due to lack of top-level `ruby2_keywords` when they are learning `ruby2_keywords`.
2. We write small applications that consist of only one script file, e.g., Slack notification script, a simple AWS Lambda, a CGI script for webhooks, etc.  I believe top-level methods are actually used in such a script.

So, I think the top-level `ruby2_keywords` is good to have in 2.7.

---Files--------------------------------
top-level-ruby2_keywords.patch (1.57 KB)


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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.