ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: nagachika00@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:99325] [Ruby master Bug#16854] Using (...) when the method name is a keyword generates error
Date: Sat, 25 Jul 2020 04:41:05 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-86720.20200725044104.38694@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16854.20200513164236.38694@ruby-lang.org

Issue #16854 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.5: DONTNEED, 2.6: DONTNEED, 2.7: REQUIRED to 2.5: DONTNEED, 2.6: DONTNEED, 2.7: DONE

ruby_2_7 be359442cb07c25fdc769431ffed3249b9016829 merged revision(s) 71c166e11e761dcaaa943f9b94da38f86ada1bdb.

----------------------------------------
Bug #16854: Using (...) when the method name is a keyword generates error
https://bugs.ruby-lang.org/issues/16854#change-86720

* Author: jamesnakagawa (James Nakagawa)
* Status: Closed
* Priority: Normal
* ruby -v: 2.7.0
* Backport: 2.5: DONTNEED, 2.6: DONTNEED, 2.7: DONE
----------------------------------------
Although I wouldn't generally recommend it, naming a method `true` is allowed. However, in combination with the new argument forwarding keyword `...`, a syntax error is generated which does not occur with other argument choices.

This came up for me on my Rails project where an enumerated database column was defined to allow the values `:true`, `:false` (not an unreasonable request in itself). Active Record's generated class tried to contain methods by these names.

Try this code for yourself:

```ruby
class Works
  def true(*args)
    puts(*args)
  end
end

Works.new.true 1, 2, 3
# => 1, 2, 3

class WontWork
  def true(...)
    puts(...)
  end
end

# => freezes
```



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

      parent reply	other threads:[~2020-07-25  4:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13 16:42 [ruby-core:98323] [Ruby master Bug#16854] Using (...) when the method name is a keyword generates error james
2020-05-13 17:32 ` [ruby-core:98325] " shevegen
2020-05-15  6:00 ` [ruby-core:98379] " nobu
2020-07-25  4:41 ` nagachika00 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-86720.20200725044104.38694@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).