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 03EEA1AE022E for ; Wed, 7 Sep 2016 16:13:25 +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 C70FBB5D8E1 for ; Wed, 7 Sep 2016 16:45:58 +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 51E8718CC81E for ; Wed, 7 Sep 2016 16:45:59 +0900 (JST) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A03D4120509; Wed, 7 Sep 2016 16:45:59 +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 3832A1204F3 for ; Wed, 7 Sep 2016 16:45:55 +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=4MSDGlIUqRodJZmrE+HpoORWweo=; b=cMFklvQRWVmge1EjLe 5zYI68B/NHCaGqU1MP7SBaKcZn3/Jb/7S2+EMMZBrH7MNPMwaG6UrH05F4O9kvdO TkhjZM84yH0bZw3Qj015I4rjpcz8/xCT/bZX52ZPXXim8rwO30xeHOJqWUYBStIT m4DO5YFyYmE7jC3gLf+NlnI50= Received: by filter0475p1mdw1.sendgrid.net with SMTP id filter0475p1mdw1.11606.57CFC5AC18 2016-09-07 07:45:48.310021282 +0000 UTC Received: from herokuapp.com (ec2-54-204-80-184.compute-1.amazonaws.com [54.204.80.184]) by ismtpd0005p1iad1.sendgrid.net (SG) with ESMTP id GD9LkMCcRTe6Ck4VcGjICg for ; Wed, 07 Sep 2016 07:45:48.151 +0000 (UTC) Date: Wed, 07 Sep 2016 07:45:48 +0000 From: sonots@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 51986 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 12694 X-Redmine-Issue-Author: sonots X-Redmine-Sender: sonots 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS5fpAZTOIUNKPHxy4KzzNncRwKqjRSHdEuzBH Uu/2drEt+mRs+EvT5DvCRO+eB1KdnSLsX5BXx2+EFV6Rb61IzqkVDGD0r215oqo+uVsFcPPrNbkewF pv2vVR2RoDlxJ4nc4El4GaZfwI5kiNn4QCuU X-ML-Name: ruby-core X-Mail-Count: 77192 Subject: [ruby-core:77192] [Ruby trunk Feature#12694] Want a String method to remove heading substr 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 #12694 has been updated by Naotoshi Seo. PHP has ltrim and rtrim (which is an alias of chop) http://php.net/manual/en/function.ltrim.php. It seems String#ltrim is fine for me. How do you think? ---------------------------------------- Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694#change-60407 * Author: Naotoshi Seo * Status: Open * Priority: Normal * Assignee: ---------------------------------------- I often write codes like: ```ruby str = 'abcdef' substr = 'abc' str[substr.size..-1] if str.start_with?(substr) #=> 'def' # or str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def' ``` I want a short hand which is something like: ```ruby str = 'abcdef' substr = 'abc' str.lstrip(substr) #=> 'def' ``` Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)` My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45 -- https://bugs.ruby-lang.org/