From: "baweaver (Brandon Weaver)" Date: 2021-09-13T03:54:04+00:00 Subject: [ruby-core:105215] [Ruby master Feature#14579] Hash value omission Issue #14579 has been updated by baweaver (Brandon Weaver). knu (Akinori MUSHA) wrote in #note-18: > We should allow it to call a (private) method if no variable with the name defined. We use methods in RSpec or with attr_reader that look like variables, and programmers don't necessarily distinguish between methods from variables when writing a program. I believe this syntax should take methods into account. I would agree that (private) methods are very useful here, especially `attr_*` methods. There are a few cases I would wonder what they do: * `@var:` - Would this work with instance/class/global/constant variables if they're valid symbols? * `a = 1; {a:, b: 3}` - Does it support mixing omissions and regular values? * `p a:, b: 3` - Does it work with implied hashes / keywords? (I think yes). I agree that `{ "#{ str }": }` should not be allowed, as it presents potential for abuse and vulnerabilities. I've [PR'd the second case on mixed values](https://github.com/ruby/ruby/pull/4829), but just considered the first with ivars and similar concepts. I'm not sure which way that should go. ---------------------------------------- Feature #14579: Hash value omission https://bugs.ruby-lang.org/issues/14579#change-93622 * 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: