You can (should) use single quotes unless you need string interpolation. myString = box_scale.gsub(' in', '"') myString.gsub!(' ft', %q{'-0"}) myString = 'N.T.S' if myString.empty? myString You can also combine the first two lines. myString = box_scale.gsub(' in', '"').gsub(' ft', %q|'-0"|)
I copy/pasted your text and it almost formatted it the way I wanted. This text formatted it as 1/4" = 1' and I want it to format as 1/4" = 1'-0" so I had to add the %Q{'-0"} to the second gsub line. I like the simpler if statement! What's the difference between the single quotes or double quotes?
@@DesignbuildsolutionsLLC I changed my code above to use %q{'-0"} Note the use of q in place of Q. %q creates a single quoted string, and the following code demonstrates simple string interpolation and how using single and double quotes work differently. x='abc' "x is #{x}" + ' | ' + 'x is #{x}'
I guess what I’m not quite getting is what the single and double quotes or q vs Q changed when both work equally in my macro. Can you give a result or describe what the example x=abc is going to return? My programming is mostly by the seat of my pants and Google.
@@DesignbuildsolutionsLLC It's about writing clear, clean code. My example just above demonstrates one difference between single and double quotes. If you NEED string interpolation, then you use double quotes, otherwise use single. They generally work the same, so in your macro, there is no functional difference. To a Ruby programmer, there is a difference, to a casual user of Ruby, not so much, until there is ...
Sorry. I’m not trying to be obtuse. What does your example return? Or how would I observe the results? And the uppercase vs lower case is about convention?
You can (should) use single quotes unless you need string interpolation.
myString = box_scale.gsub(' in', '"')
myString.gsub!(' ft', %q{'-0"})
myString = 'N.T.S' if myString.empty?
myString
You can also combine the first two lines.
myString = box_scale.gsub(' in', '"').gsub(' ft', %q|'-0"|)
I copy/pasted your text and it almost formatted it the way I wanted. This text formatted it as 1/4" = 1' and I want it to format as 1/4" = 1'-0" so I had to add the %Q{'-0"} to the second gsub line.
I like the simpler if statement!
What's the difference between the single quotes or double quotes?
@@DesignbuildsolutionsLLC
I changed my code above to use %q{'-0"}
Note the use of q in place of Q. %q creates a single quoted string, and the following code demonstrates simple string interpolation and how using single and double quotes work differently.
x='abc'
"x is #{x}" + ' | ' + 'x is #{x}'
I guess what I’m not quite getting is what the single and double quotes or q vs Q changed when both work equally in my macro.
Can you give a result or describe what the example x=abc is going to return? My programming is mostly by the seat of my pants and Google.
@@DesignbuildsolutionsLLC
It's about writing clear, clean code. My example just above demonstrates one difference between single and double quotes. If you NEED string interpolation, then you use double quotes, otherwise use single. They generally work the same, so in your macro, there is no functional difference. To a Ruby programmer, there is a difference, to a casual user of Ruby, not so much, until there is ...
Sorry. I’m not trying to be obtuse. What does your example return? Or how would I observe the results?
And the uppercase vs lower case is about convention?