How do I remove leading whitespace chars from Ruby HEREDOC?

后端 未结 11 711
误落风尘
误落风尘 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条回答
  •  没有蜡笔的小新
    2020-11-28 22:40

    another easy to remember option is to use unindent gem

    require 'unindent'
    
    p <<-end.unindent
        hello
          world
      end
    # => "hello\n  world\n"  
    

提交回复
热议问题