Method: String#quote_if_necessary

Defined in:
lib/openc3/core_ext/string.rb

#quote_if_necessary(quote_char = '"') ⇒ String

Adds quotes if the string contains whitespace

Parameters:

  • quote_char (String) (defaults to: '"')

    The quote character to add if necessary

Returns:

  • (String)

    quoted string if necessary



358
359
360
361
362
363
364
# File 'lib/openc3/core_ext/string.rb', line 358

def quote_if_necessary(quote_char = '"')
  if /\s/.match?(self)
    return quote_char + self + quote_char
  else
    return self
  end
end