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

Version Path
dpl-2.0.3.beta.4 lib/dpl/helper/squiggle.rb
dpl-2.0.3.beta.3 lib/dpl/helper/squiggle.rb
dpl-2.0.3.beta.2 lib/dpl/helper/squiggle.rb
dpl-2.0.3.beta.1 lib/dpl/helper/squiggle.rb
dpl-2.0.2.beta.1 lib/dpl/helper/squiggle.rb
dpl-2.0.0.beta.3 lib/dpl/helper/squiggle.rb
dpl-2.0.0.beta.2 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.14 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.13 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.12 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.11 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.10 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.9 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.8 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.7 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.6 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.5 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.2 lib/dpl/helper/squiggle.rb
dpl-2.0.0.alpha.1 lib/dpl/helper/squiggle.rb