From: sylvain.joyeux@...4x.org Date: 2020-08-21T20:37:18+00:00 Subject: [ruby-core:99668] [Ruby master Bug#16853] calling bla(hash, **kw) with a string-based hash passes the strings into **kw (worked < 2.7) Issue #16853 has been updated by sylvain.joyeux (Sylvain Joyeux). > If there is a call like foo(**h), and h has both Symbol and non-Symbol keys, in <2.7 the Hash is "split" which I find extremely confusing and it's also slowing things down by always having to consider "there might be an extra positional argument". Keyword splat would not allow anything but symbols as keys pre-2.7. ~~~ irb(main):001:0> h = { k: 2, "c" => 20 } => {:k=>2, "c"=>20} irb(main):002:0> def m(**kw) irb(main):003:1> end => :m irb(main):004:0> m(**h) Traceback (most recent call last): 4: from /home/doudou/.rbenv/versions/2.6.5/bin/irb:23:in `
' 3: from /home/doudou/.rbenv/versions/2.6.5/bin/irb:23:in `load' 2: from /home/doudou/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `' 1: from (irb):4 TypeError (hash key "c" is not a Symbol) irb(main):005:0> ~~~ I do want to apologize for my "for Rails" comment. This was unfair to the core team's work. When it comes to optimization, though, I would assume that the keywords are all symbols would open a lot more doors. ---------------------------------------- Bug #16853: calling bla(hash, **kw) with a string-based hash passes the strings into **kw (worked < 2.7) https://bugs.ruby-lang.org/issues/16853#change-87154 * Author: sylvain.joyeux (Sylvain Joyeux) * Status: Rejected * Priority: Normal * ruby -v: 2.7.1p83 * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- The following code ~~~ def bla(hash = {}, **kw) puts "H: #{hash}" puts "K: #{kw}" end bla "some" => "string" ~~~ **silently** outputs the following (no warnings about deprecation of keyword parameters-from-hash) ~~~ H: {} K: {"some"=>"string"} ~~~ While 2.6.5 (and versions before it) gave ~~~ H: {"some"=>"string"} K: {} ~~~ I would expect "the warning" that started appearing in 2.7, and **definitely** not having strings in a keyword argument hash. -- https://bugs.ruby-lang.org/ Unsubscribe: