Rushi Patel

June 12, 2024

[Tech][Ruby] Fun comparison: STRIP, SQUEEZE, SQUISH

Here's a fun comparison between STRIP, SQUEEZE, SQUISH with an example:


Consider a string:
name = " Rushi   Patel "

STRIP:
name.strip
Output: "Rushi   Patel"
Removes the spaces from the START and END of a string

SQUEEZE:
name.squeeze
Output: " Rushi Patel "
Literally squeezes the string, i.e  squishes down any INTERNAL repeating whitespace to a SINGLE space.

SQUISH:
name.squish
Output: "Rushi Patel"
Squish does both strip and squeeze. It's not directly available in Ruby, but it's made available in Rails. It's very useful.



Written by,
Rushi Patel

About Rushi Patel

Keep scrolling or press my profile icon at the top to view all my posts. Happy reading!