[#91458] [Ruby trunk Feature#4475] default variable name for parameter — matz@...
Issue #4475 has been updated by matz (Yukihiro Matsumoto).
3 messages
2019/02/07
[ruby-core:91442] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing`
From:
eregontp@...
Date:
2019-02-06 19:54:41 UTC
List:
ruby-core #91442
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/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>