* [ruby-core:90258] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing`
[not found] <redmine.issue-15374.20181203110716@ruby-lang.org>
@ 2018-12-03 11:07 ` manga.osyo
2018-12-03 15:29 ` [ruby-core:90265] " hanmac
` (5 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: manga.osyo @ 2018-12-03 11:07 UTC (permalink / raw)
To: ruby-core
Issue #15374 has been reported by osyo (manga osyo).
----------------------------------------
Feature #15374: Proposal: Enable refinements to `#method_missing`
https://bugs.ruby-lang.org/issues/15374
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:90265] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing`
[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 ` hanmac
2018-12-04 11:22 ` [ruby-core:90283] " manga.osyo
` (4 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: hanmac @ 2018-12-03 15:29 UTC (permalink / raw)
To: ruby-core
Issue #15374 has been updated by Hanmac (Hans Mackowiak).
i always like the fun you can do with method_missing, but for your example, method_missing always use a symbol for the name, so name.to_sym should just return self or did you do that on purpose?
----------------------------------------
Feature #15374: Proposal: Enable refinements to `#method_missing`
https://bugs.ruby-lang.org/issues/15374#change-75380
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:90283] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing`
[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 ` manga.osyo
2019-02-06 19:54 ` [ruby-core:91442] " eregontp
` (3 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: manga.osyo @ 2018-12-04 11:22 UTC (permalink / raw)
To: ruby-core
Issue #15374 has been updated by osyo (manga osyo).
oops, that's right.
----------------------------------------
Feature #15374: Proposal: Enable refinements to `#method_missing`
https://bugs.ruby-lang.org/issues/15374#change-75395
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:91442] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing`
[not found] <redmine.issue-15374.20181203110716@ruby-lang.org>
` (2 preceding siblings ...)
2018-12-04 11:22 ` [ruby-core:90283] " manga.osyo
@ 2019-02-06 19:54 ` eregontp
2019-02-07 4:13 ` [ruby-core:91446] " manga.osyo
` (2 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: eregontp @ 2019-02-06 19:54 UTC (permalink / raw)
To: ruby-core
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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:91446] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing`
[not found] <redmine.issue-15374.20181203110716@ruby-lang.org>
` (3 preceding siblings ...)
2019-02-06 19:54 ` [ruby-core:91442] " eregontp
@ 2019-02-07 4:13 ` manga.osyo
2019-02-07 7:59 ` [ruby-core:91464] " matz
2019-02-08 0:02 ` [ruby-core:91484] " manga.osyo
6 siblings, 0 replies; 7+ messages in thread
From: manga.osyo @ 2019-02-07 4:13 UTC (permalink / raw)
To: ruby-core
Issue #15374 has been updated by osyo (manga osyo).
Yes, it will be the specification of Ruby.
method_missing has a large side effect.
So can use `using` to control by context.
```ruby
module HashWithAsscessKeyToMethod
refine Hash do
# name is Symbol or String
def method_missing(name)
self[name] || self[name.to_s]
end
end
end
# Do not want to use Hash#method_missing
hash = { name: "homu", age: 14 }
pp hash[:name] # OK
# pp hash.name # NG
# Do want to use Hash#method_missing
using HashWithAsscessKeyToMethod
pp hash.name # OK
```
User can choose.
----------------------------------------
Feature #15374: Proposal: Enable refinements to `#method_missing`
https://bugs.ruby-lang.org/issues/15374#change-76705
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:91464] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing`
[not found] <redmine.issue-15374.20181203110716@ruby-lang.org>
` (4 preceding siblings ...)
2019-02-07 4:13 ` [ruby-core:91446] " manga.osyo
@ 2019-02-07 7:59 ` matz
2019-02-08 0:02 ` [ruby-core:91484] " manga.osyo
6 siblings, 0 replies; 7+ messages in thread
From: matz @ 2019-02-07 7:59 UTC (permalink / raw)
To: ruby-core
Issue #15374 has been updated by matz (Yukihiro Matsumoto).
Status changed from Open to Rejected
I don't see any real-world usage of allowing `#method_missing` refinable. Maybe it can be used only for tricks and obfusticated code.
Matz.
----------------------------------------
Feature #15374: Proposal: Enable refinements to `#method_missing`
https://bugs.ruby-lang.org/issues/15374#change-76725
* Author: osyo (manga osyo)
* Status: Rejected
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:91484] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing`
[not found] <redmine.issue-15374.20181203110716@ruby-lang.org>
` (5 preceding siblings ...)
2019-02-07 7:59 ` [ruby-core:91464] " matz
@ 2019-02-08 0:02 ` manga.osyo
6 siblings, 0 replies; 7+ messages in thread
From: manga.osyo @ 2019-02-08 0:02 UTC (permalink / raw)
To: ruby-core
Issue #15374 has been updated by osyo (manga osyo).
OK, Thanks matz :)
----------------------------------------
Feature #15374: Proposal: Enable refinements to `#method_missing`
https://bugs.ruby-lang.org/issues/15374#change-76743
* Author: osyo (manga osyo)
* Status: Rejected
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-02-08 0:03 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[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 ` [ruby-core:91442] " eregontp
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
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).