Does anyone know of a Ruby stone (or native or native syntax, for that matter) that works with external string quotation marks?
I write methods over and over again:
remove_outer_quotes_if_quoted( myString, chars ) -> aString add_outer_quotes_unless_quoted( myString, char ) -> aString
The first tests are myString to see if its start and end characters match the same character in chars . If so, it returns a string with quotes removed. Otherwise, it returns it unchanged. chars by default, is assigned a list of quotation mark characters.
The second test is myString to find out if it starts and ends with char . If so, it returns the string unchanged. If not, it returns a string with char , attached before and after, and any implemented char event is executed with a backslash. char defaults to the first character in the default character list.
(My manual methods do not have such detailed names, of course.)
I looked at similar methods in public repositories, but cannot find anything like it. Am I the only one who has to do this? If not, how does everyone do it?
source share