Project

General

Profile

Actions

Feature #15286

closed

Proposal: Add Kernel.#expand(*args)

Added by osyo (manga osyo) over 5 years ago. Updated over 5 years ago.

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

Description

This is a suggestion for Hash shorthand.

Kernel.#expand(*args) is expand local variable and method to Hash.
*args is method or local variable names.

Example

def meth
  "meth"
end
a, b, c = 1, 2, 3

# #expand args is local variable or method names
# Expand to { a: a, b: b: meth: meth }
p expand(:a, :b, :meth)
# => {:a=>1, :b=>2, :meth=>"meth"}

# Error: `expand': undefined method `hoge' for main:Object (NoMethodError)
p expand(:hoge)

What can be expanded,

  • local variable
  • method

and, If there are duplicate names, prioritize local variable.

def meth
   "meth"
end
meth = 42

p expand(:meth)
# => {:meth=>42}

pull request: https://github.com/ruby/ruby/pull/2006


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #15236: add support for hash shorthandRejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0