Macro to change Box Scale Format | Chief Architect

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 8

  • @EricOnChiefArchitect
    @EricOnChiefArchitect 2 ปีที่แล้ว

    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"|)

    • @DesignbuildsolutionsLLC
      @DesignbuildsolutionsLLC  2 ปีที่แล้ว

      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?

    • @EricOnChiefArchitect
      @EricOnChiefArchitect 2 ปีที่แล้ว

      @@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}'

    • @DesignbuildsolutionsLLC
      @DesignbuildsolutionsLLC  2 ปีที่แล้ว

      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.

    • @EricOnChiefArchitect
      @EricOnChiefArchitect 2 ปีที่แล้ว

      @@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 ...

    • @DesignbuildsolutionsLLC
      @DesignbuildsolutionsLLC  2 ปีที่แล้ว

      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?