From: manga.osyo@... Date: 2019-02-07T04:13:44+00:00 Subject: [ruby-core:91446] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing` 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/ Unsubscribe: