Sha256: be01d8c975412c31485b4d61a06432a346591f0c7e8d68e0bb84660b7ac17a89
Contents?: true
Size: 620 Bytes
Versions: 14
Compression:
Stored size: 620 Bytes
Contents
class String # Strips indentation in heredocs. # # For example in # # if options[:usage] # puts <<-USAGE.strip_heredoc # This command does such and such. # # Supported options are: # -h This message # ... # USAGE # end # # the user would see the usage message aligned against the left margin. # # Technically, it looks for the least indented line in the whole string, and removes # that amount of leading whitespace. def strip_heredoc indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0 gsub(/^[ \t]{#{indent}}/, '') end end
Version data entries
14 entries across 14 versions & 2 rubygems