From: amd@gurge.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:76120] [Ruby trunk Feature#11735] Porting String#squish and String#squish! from Ruby on Rails' Active Support
Date: Thu, 23 Jun 2016 17:33:15 +0000 [thread overview]
Message-ID: <redmine.journal-59324.20160623173315.635362c9906cd8fe@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11735.20151124193633@ruby-lang.org
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 <pre> 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/
next prev parent reply other threads:[~2016-06-23 16:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-11735.20151124193633@ruby-lang.org>
2015-11-24 19:36 ` [ruby-core:71658] [Ruby trunk - Feature #11735] [Open] Porting String#squish and String#squish! from Ruby on Rails' Active Support s
2015-11-24 20:40 ` [ruby-core:71663] " Eric Wong
2015-11-24 19:38 ` [ruby-core:71659] [Ruby trunk - Feature #11735] " s
2015-11-24 19:42 ` [ruby-core:71660] " s
2015-11-25 4:20 ` [ruby-core:71676] " nobu
2015-11-25 17:03 ` [ruby-core:71685] " deivid.rodriguez
2015-12-07 7:50 ` [ruby-core:71890] " ko1
2015-12-07 7:51 ` [ruby-core:71891] " nobu
2015-12-07 14:19 ` [ruby-core:71906] " s
2016-05-18 1:22 ` [ruby-core:75589] [Ruby trunk Feature#11735] " shyouhei
2016-05-19 17:57 ` [ruby-core:75616] " amd
2016-05-20 2:38 ` [ruby-core:75631] " shyouhei
2016-06-23 17:33 ` amd [this message]
2016-06-24 8:02 ` [ruby-core:76134] " shyouhei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-59324.20160623173315.635362c9906cd8fe@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).