From: shevegen@... Date: 2018-11-07T00:33:44+00:00 Subject: [ruby-core:89739] [Ruby trunk Feature#15286] Proposal: Add Kernel.#expand(*args) Issue #15286 has been updated by shevegen (Robert A. Heiler). I think one possible question in regards to the suggestion here is whether the above method may be useful on its own, even without a shorthand syntax for Hash. (This is really just a question; I personally am not really having any strong pro/con opinion.) I also understand that using a method is different compared to the other two proposals. For example, { a } { a: a} and {x, y} {x: x, y: y} is different to: meth = 42 p expand(:meth) # => {:meth=>42} So using a method is different to the other two proposals (in the two older issue request, by Ignatius and Shugo Maeda). Perhaps one or more use cases could be described for a new method to be useful even without the hash shorthand notation? I can not think of a good one right now but perhaps others have some ideas. ---------------------------------------- Feature #15286: Proposal: Add Kernel.#expand(*args) https://bugs.ruby-lang.org/issues/15286#change-74782 * Author: osyo (manga osyo) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- This is a suggestion for Hash shorthand. * [add support for hash shorthand](https://bugs.ruby-lang.org/issues/15236) `Kernel.#expand(*args)` is expand `local variable` and `method` to Hash. `*args` is method or local variable names. ## Example ```ruby 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. ```ruby def meth "meth" end meth = 42 p expand(:meth) # => {:meth=>42} ``` pull request: https://github.com/ruby/ruby/pull/2006 -- https://bugs.ruby-lang.org/ Unsubscribe: