Sha256: bf6e79938c04aee8762f8500b3145a7decf60576edc445dd115181af2e32b4d9
Contents?: true
Size: 799 Bytes
Versions: 19
Compression:
Stored size: 799 Bytes
Contents
# Beloved squiggly heredocs did not exist in Ruby 2.1, which we still want to # support, so let's give kudos with a method `sq`. module Squiggle # Outdents each line on a multiline string by the number of leading # whitespace characters on the first line. # # This method exists so we can unindet heredoc strings the same way that # Ruby 2.2's squiggly heredocs work, but still support Ruby 2.1 for the # time being. # # For example: # # str = sq(<<-str) # This multiline string will be outdented by two characters, # so the extra indentation on this line will be kept, # while this line sits on the same level as the first line. # str def sq(str) width = str =~ /( *)\S/ && $1.size str.lines.map { |line| line.gsub(/^ {#{width}}/, '') }.join end end
Version data entries
19 entries across 19 versions & 1 rubygems