From: eregontp@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:91442] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing`
Date: Wed, 06 Feb 2019 19:54:41 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-76700.20190206195440.ce8fc3f595724cef@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15374.20181203110716@ruby-lang.org
Issue #15374 has been updated by Eregon (Benoit Daloze).
This wouldn't work, e.g. for `hash.first`, or any existing method of `Hash`.
What's a useful case for this feature?
----------------------------------------
Feature #15374: Proposal: Enable refinements to `#method_missing`
https://bugs.ruby-lang.org/issues/15374#change-76700
* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Proposal enable refinements to `#method_missing`.
It can be used in the following cases.
```ruby
# Access key value with method
using Module.new {
refine Hash do
# name is Symbol or String
def method_missing(name)
self[name.to_sym] || self[name.to_s]
end
end
}
hash = { name: "homu", "age" => 14 }
pp hash.name
# => "homu"
pp hash.age
# => "age"
```
`method_missing` is hard hacking.
I would like to use Refinements with `method_missing`.
pull request: https://github.com/ruby/ruby/pull/2036
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2019-02-06 19:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-15374.20181203110716@ruby-lang.org>
2018-12-03 11:07 ` [ruby-core:90258] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing` manga.osyo
2018-12-03 15:29 ` [ruby-core:90265] " hanmac
2018-12-04 11:22 ` [ruby-core:90283] " manga.osyo
2019-02-06 19:54 ` eregontp [this message]
2019-02-07 4:13 ` [ruby-core:91446] " manga.osyo
2019-02-07 7:59 ` [ruby-core:91464] " matz
2019-02-08 0:02 ` [ruby-core:91484] " manga.osyo
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-76700.20190206195440.ce8fc3f595724cef@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).