12/08/2018, 13:35
Strip vs Squish
Sample " hello world " . strip = > "hello world" " hello world " . squish = > "hello world" What's difference? Strip Ruby method Returns the string, remove white spaces only at the leading and trailing Squish Rails method Returns the string, ...
Sample
" hello world ".strip => "hello world" " hello world ".squish => "hello world"
What's difference?
Strip
- Ruby method
- Returns the string, remove white spaces only at the leading and trailing
Squish
- Rails method
- Returns the string, first removing all whitespace on both ends of the string, and then changing remaining consecutive whitespace groups into one space each.
How to use squish in ruby without rails?
Very simple
" hello world".split.join(" ") => "hello world"