From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.5 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.1 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id E9D1E1F453 for ; Wed, 17 Oct 2018 08:52:03 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 3EB6F120A59; Wed, 17 Oct 2018 17:52:01 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id A0AF1120965 for ; Wed, 17 Oct 2018 17:51:59 +0900 (JST) Received: by filter0033p3las1.sendgrid.net with SMTP id filter0033p3las1-26428-5BC6F82D-23 2018-10-17 08:51:57.644710712 +0000 UTC m=+955631.599835756 Received: from herokuapp.com (ec2-54-162-21-250.compute-1.amazonaws.com [54.162.21.250]) by ismtpd0002p1iad2.sendgrid.net (SG) with ESMTP id BuVmTCoAR42gCmR5SXVt-g for ; Wed, 17 Oct 2018 08:51:57.495 +0000 (UTC) Date: Wed, 17 Oct 2018 08:51:57 +0000 (UTC) From: naruse@airemix.jp To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 64825 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15231 X-Redmine-Issue-Author: mame X-Redmine-Sender: naruse 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS4TLkSqoXqQd3ol7Ks13KaZ5kPyMJgl2n9XJz CNTqsBN0AzMxCKAdi4Em+5KTDbB/F7XpXOCHxWT4/X5882I8jQk24Zcb89mRMJFEOhc6Hi9XcbExSE K18OBgTkMu2q8UdHVkWCPt8R8wSWkcjxgI7Bg/5VDRzuPAIDoYUzx3MP1w== X-ML-Name: ruby-core X-Mail-Count: 89440 Subject: [ruby-core:89440] [Ruby trunk Feature#15231] Remove `Object#=~` 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 #15231 has been updated by naruse (Yui NARUSE). rubocop should alert `obj =~ re` to fix as `re =~ obj`. ---------------------------------------- Feature #15231: Remove `Object#=~` https://bugs.ruby-lang.org/issues/15231#change-74478 * Author: mame (Yusuke Endoh) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- `Object#=~` receives (and just discards) an argument, and always returns nil. What purpose is this method for? The following behavior that `Object#=~` caused was confusing to me. ``` ["foo"] =~ /foo/ #=> nil ``` More precisely: the actual example that I encountered was to parse coverage data from output of coverage measurement tool by using `Open3.capture2`: ``` out = Open3.capture2("gcov", ...) # BUG: `out, =` was intended if out ~= /lines\.*: *(\d+\.\d+)%/ ... end ``` Obviously, I forgot a comma to receive the return value of `Open3.capture2`. The method returns a two-element array, and `out ~=` calls `Object#=~`, which hided the bug. (Worse, I took several tens of minutes to debug it because I first thought that this is a bug of regexp, and spent tweaking the regexp.) I guess `Object#=~` was intended for general pattern matching, but presently the role was taken over by `Object#===`. So. How about removing `Object#=~`? Concerns: * @usa said `NilClass#=~` should be newly introduced because of: `if gets =~ /re/` * `Object#!~` is difficult to remove: some classes define only `#=~`, and expect `Object#!~` to delegate to `#=~`. -- https://bugs.ruby-lang.org/