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.6 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 5E2ED1F453 for ; Sat, 20 Oct 2018 00:50:13 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 773E4121176; Sat, 20 Oct 2018 09:50:10 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id D95B5121066 for ; Sat, 20 Oct 2018 09:50:07 +0900 (JST) Received: by filter0125p3las1.sendgrid.net with SMTP id filter0125p3las1-419-5BCA7BBC-1F 2018-10-20 00:50:04.885826005 +0000 UTC m=+99115.890034588 Received: from herokuapp.com (ec2-54-198-118-37.compute-1.amazonaws.com [54.198.118.37]) by ismtpd0023p1mdw1.sendgrid.net (SG) with ESMTP id 49agU9mlQZ2-3TnXU9GD4g for ; Sat, 20 Oct 2018 00:50:04.778 +0000 (UTC) Date: Sat, 20 Oct 2018 00:50:05 +0000 (UTC) From: zn@mbf.nifty.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 64869 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15231 X-Redmine-Issue-Author: mame X-Redmine-Sender: znz 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS5UNCq0W7aztbeTA5LKhsh1T7MW2yS3VOp2cR ZcfcEyyAsqlFTubxQjHGpayB75ZP7e+OOZlmWeUrTR9tE74eGoXiida0NN8xsZ3Y1oVsVjEp942uxD hJlWRWmTOP4nwHtVyK/RUoUh2nj3VK8BquRD X-ML-Name: ruby-core X-Mail-Count: 89483 Subject: [ruby-core:89483] [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 znz (Kazuhiro NISHIYAMA). ```ruby "" =~ "" #=> TypeError (type mismatch: String given) ``` ---------------------------------------- Feature #15231: Remove `Object#=~` https://bugs.ruby-lang.org/issues/15231#change-74524 * 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. ```RUBY ["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`: ```RUBY 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 hid 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/