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 F17A11A60098 for ; Fri, 24 Jun 2016 01:58:48 +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 5FF47B5D8AB for ; Fri, 24 Jun 2016 02:33:42 +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 5DEA418CC81A for ; Fri, 24 Jun 2016 02:33:42 +0900 (JST) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 1B5A5120443; Fri, 24 Jun 2016 02:33:41 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id 781CC120484 for ; Fri, 24 Jun 2016 02:33:33 +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=8tKTVuEd5W3m9acHlC46YOIcj9I=; b=oI/DU4Ga0ByfPV3Cr/ Tj4ZJ+etveL9jbKyduWV7+M3YQzIss3pLGbWFpK23v4w/UGzX5W0vtHWP+SDGwEl dULIbUz+xKwXGbXD5gV4VQry1ElVNMM8Qe2Q9RVTu7UYtaFMqoNYOCb1OqX9BQV+ +q1QHZWs1zuNygw4E+7MlmhL0= Received: by filter0805p1mdw1.sendgrid.net with SMTP id filter0805p1mdw1.22812.576C1D5B5B 2016-06-23 17:33:15.849122896 +0000 UTC Received: from herokuapp.com (ec2-54-87-67-136.compute-1.amazonaws.com [54.87.67.136]) by ismtpd0002p1iad1.sendgrid.net (SG) with ESMTP id 41gVK9KwRt-eh53J-4L17A Thu, 23 Jun 2016 17:33:15.656 +0000 (UTC) Date: Thu, 23 Jun 2016 17:33:15 +0000 From: amd@gurge.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 50837 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11735 X-Redmine-Issue-Author: sikachu X-Redmine-Issue-Assignee: matz X-Redmine-Sender: gurgeous 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS5sI2ZVv1Mvz4t/YZDMvcqz70cd7XTXoYd1gs 0mpAed7+oawIC287PaA0cwrSGYK1y8dkz3gtUC6o7wEuqdsLtCnExsYHwNC/f/0EnUgKilGhHohC5g nMZ/RyZF4g7aEQ9f2kfpqO2MdmP/XaDWG/6n X-ML-Name: ruby-core X-Mail-Count: 76120 Subject: [ruby-core:76120] [Ruby trunk Feature#11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support 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 #11735 has been updated by Adam Doppelt. Shyouhei Urabe wrote: > I had no pro et contra to the proposal until now. From what you said I started thinking squish can be a bad smell of indiscreet data treatment. I think you're missing the point here. Squish is used to cleanup whitespace. If you want to preserve whitespace, don't call it. There are many, many, many (many) situations where cleaning up whitespace is desirable and squish is perfect. Yes, I actually need to destroy newlines, smash spaces together, and annihilate
 tags. This is incredibly common. That's why I use squish. If I didn't want to do those things I would not use squish.

----------------------------------------
Feature #11735: Porting String#squish and String#squish! from Ruby on Rails' Active Support
https://bugs.ruby-lang.org/issues/11735#change-59324

* Author: Prem Sichanugrist
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Hi,

I have been using this `String#squish` method so many time when I'm using Rails, and I think it should be a useful addition to core.

Here's the method on Rails' documentation: http://api.rubyonrails.org/v4.2.5/classes/String.html#method-i-squish

This method is very useful when you have to write a multi-line string using heredoc, but you actually does not care about the white-spaces before, after, and in-between the string.

For example:

~~~ruby
<<-SQL.squish
  SELECT *
  FROM users
  WHERE users.username = 'sikachu'
SQL
#=> "SELECT * FROM users WHERE users.username='sikachu'"
~~~

Another example usage is when you are on the project that have a line length code standard, and you have to write a long warning message that needs to be printed to stdout:

~~~ruby
puts <<-WARNING.squish
  Unable to connect to the server. Please double-check that you are currently
  connecting to the internet and your proxy server is working.
WARNING
#=> Unable to connect to the server. Please double-check that you are currently connecting to the internet and your proxy server is working.
~~~

By the way, this is my first patch and my first time writing something in C, so there might be something that does not look right to you. I'll happy to revise this patch (and learn about C in the process!) from your feedback.

Thank you,
Prem

---Files--------------------------------
0001-Introduce-String-squish-and-String-squish.patch (4.67 KB)


-- 
https://bugs.ruby-lang.org/