How do I remove leading whitespace chars from Ruby HEREDOC?

后端 未结 11 710
误落风尘
误落风尘 2020-11-28 22:09

I\'m having a problem with a Ruby heredoc i\'m trying to make. It\'s returning the leading whitespace from each line even though i\'m including the - operator, which is supp

11条回答
  •  猫巷女王i
    2020-11-28 22:56

    Note: As @radiospiel pointed out, String#squish is only available in the ActiveSupport context.


    I believe ruby's String#squish is closer to what you're really looking for:

    Here is how I would handle your example:

    def distinct_count
      <<-SQL.squish
        SELECT
          CAST('#{name}' AS VARCHAR(30)) as COLUMN_NAME,
          COUNT(DISTINCT #{name}) AS DISTINCT_COUNT
          FROM #{table.call}
      SQL
    end
    

提交回复
热议问题