If you want to remove only leading and trailing whitespace (like PHP's trim) you can use .strip, but if you want to remove all whitespace, you can use .gsub(/\s+/, "") instead .
.strip
.gsub(/\s+/, "")
s = "I have white space".delete(' ')
And to emulate PHP's trim() function:
trim()
s = " I have leading and trailing white space ".strip
Related answer:
" clean up my edges ".strip
returns
"clean up my edges"