From: "knu (Akinori MUSHA)" Date: 2021-09-13T04:10:25+00:00 Subject: [ruby-core:105217] [Ruby master Feature#14579] Hash value omission Issue #14579 has been updated by knu (Akinori MUSHA). baweaver (Brandon Weaver) wrote in #note-19: > * `@var:` - Would this work with instance/class/global/constant variables if they're valid symbols? No, because we didn't change the symbol key syntax. `{ @var: @var }` is not valid, so `{ @var: }` isn't either. The same goes for `$var` and `@@var`. > * `a = 1; {a:, b: 3}` - Does it support mixing omissions and regular values? Yes. > * `p a:, b: 3` - Does it work with implied hashes / keywords? (I think yes). Yes, but beware when you omit the last value without the closing parenthesis. The interpreter will look further past the line end for a value. ---------------------------------------- Feature #14579: Hash value omission https://bugs.ruby-lang.org/issues/14579#change-93624 * Author: shugo (Shugo Maeda) * Status: Closed * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- How about to allow value omission in Hash literals: ```ruby x = 1 y = 2 h = {x:, y:} p h #=> {:x=>1, :y=>2} ``` And in keyword arguments: ```ruby def login(username: ENV["USER"], password:) p(username:, password:) end login(password: "xxx") #=> {:username=>"shugo", :password=>"xxx"} ``` ---Files-------------------------------- hash_value_omission.diff (619 Bytes) -- https://bugs.ruby-lang.org/ Unsubscribe: