From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id C3EDC1AC0041 for ; Sun, 21 Aug 2016 23:56:11 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 70632B5D8BC for ; Mon, 22 Aug 2016 00:29:15 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 5185918CC81B for ; Mon, 22 Aug 2016 00:29:16 +0900 (JST) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B47F1120434; Mon, 22 Aug 2016 00:29:14 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id 34081120400 for ; Mon, 22 Aug 2016 00:29:10 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=ayzzesupxaU7yu192gBQUWuAMws=; b=aT0mxaVJnv/V7mZ3ex /S/wm/QmGl67sf4RpXL3+HN6Oy6QMckS6gQncynxjkXvnbBg83FvB+9B/Qvn45hd ED1vcgGeJqhdmtU9S/0MCQg/Ueh8i86Jtfe2f0PrfsAcP6QPdMyIzgWkrPL14Uug +ZudMy3ZCXt/mR7vJtG94RVqc= Received: by filter0691p1mdw1.sendgrid.net with SMTP id filter0691p1mdw1.17579.57B9C8BD12 2016-08-21 15:29:01.557971351 +0000 UTC Received: from herokuapp.com (ec2-54-163-24-140.compute-1.amazonaws.com [54.163.24.140]) by ismtpd0002p1iad1.sendgrid.net (SG) with ESMTP id LVMcEs55THWrwSPc1kHywA Sun, 21 Aug 2016 15:29:01.630 +0000 (UTC) Date: Sun, 21 Aug 2016 15:29:01 +0000 From: eregontp@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 51782 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 10856 X-Redmine-Issue-Author: seantheprogrammer X-Redmine-Sender: Eregon X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4qYUkPiRPf2DcWCR/bYekJK5eHFomJsENBUh Lv/OXm7rm6ryoe68ewaFZ5tHPtYYclA5LQL7wrQQBARfKb3ByrJfJEbv+GGCEYplD/e6rar1pR+zgb flHa1WxaIwuE2dT7RAnNC2oW9LXna6m0zYs5DRsGuTk+xVJxsC8tWfYGoQ== X-SendGrid-Contentd-ID: {"test_id":"1471793342"} X-ML-Name: ruby-core X-Mail-Count: 76996 Subject: [ruby-core:76996] [Ruby trunk Bug#10856] Splat with empty keyword args gives unexpected results X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #10856 has been updated by Benoit Daloze. Guyren Howe wrote: > I believe this behavior is wrong and should be fixed. > > This gets in the way of simple functional programming idioms. eg "Call each of these functions with these args until one doesn't fail" There is a simple fix for your use-case, if you just want to fowrard arguments, don't use ** at all: (it's not like in Python, keyword arguments are less separated form normal arguments) > ~~~ ruby > class FnSeries > def initialize(*fns) > @fns = fns > end > > def call(*args) > @fns.each do |fn| > begin > return fn.call(*args) > rescue Exception => e > end > end > end > ~~~ Marc-Andre Lafortune wrote: > I feel this has to be fixed. > > foo(**{}) should === foo(**Hash.new) in all cases, and I feel it should not raise an error. I agree, it's highly inconsistent that: ~~~ ruby def foo(*args); args; end foo(**{}) # => [] h={} foo(**h) # => [{}] foo(h) # => [{}] ~~~ ---------------------------------------- Bug #10856: Splat with empty keyword args gives unexpected results https://bugs.ruby-lang.org/issues/10856#change-60220 * Author: Sean Griffin * Status: Open * Priority: Normal * Assignee: * ruby -v: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin13] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- When keyword args are passed to a method with splat, and there are no keyword args, an empty hash is sent. I would expect no argument to be given, same as splat with an empty array. For example: def foo end foo(**{}) This causes an argument error, as an empty hash is passed. I would expect the same behavior as def foo end foo(*[]) -- https://bugs.ruby-lang.org/