Project

General

Profile

Actions

Feature #15374

closed

Proposal: Enable refinements to `#method_missing`

Added by osyo (manga osyo) about 6 years ago. Updated almost 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:90258]

Description

Proposal enable refinements to #method_missing.
It can be used in the following cases.

# 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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0