Sha256: a3bf3b27f5d3b403d1eb3380ebbbdfa9ced9812bca52ab16a125afb0cafab610
Contents?: true
Size: 725 Bytes
Versions: 17
Compression:
Stored size: 725 Bytes
Contents
# Borrowed from activesupport, but without the :try method 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 matches = scan(/^[ \t]*(?=\S)/).min indent = (matches.respond_to? :size) ? matches.size : 0 gsub(/^[ \t]{#{indent}}/, '') end end
Version data entries
17 entries across 17 versions & 2 rubygems