I have a string in Ruby on which I\'m calling the strip method to remove the leading and trailing whitespace. e.g.
s = \"12345 \"
s.strip
H
To complete the options shown here, there is the "Existence Check Shorthand", recommended in the Ruby Style Guide:
Use
&&=to preprocess variables that may or may not exist. Using&&=will change the value only if it exists [means, is notnil], removing the need to check its existence withif.
So in your case you would do:
s = "12345 "
s &&= s.strip