Issue #11735 has been updated by Shyouhei Urabe.


Adam Doppelt wrote:
> Getting input from a user? squish

I guess you have never had a user from CJKV cultures.

> Cleaning up an iffy array.join? squish

This is a huge NO.  It destroys JSON.

> Pulling data from a web crawl? squish

Also NO.  It destroys <pre>.

> Normalizing concatenated data? squish

This could be OK depending on the "normalization" you want.

> Squish squish squish. 60k hits on github for Ruby squish. Just squish it. Squish it into core, please.

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 hope I'm wrong.

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

* 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/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>