aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/compat/extend/string.rb
blob: 9d1f665576c797916725a01d94689ee9e87b38de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class String
  def undent
    odeprecated "<<-EOS.undent", "<<~EOS"
    gsub(/^[ \t]{#{(slice(/^[ \t]+/) || '').length}}/, "")
  end
  alias unindent undent

  # eg:
  #   if foo then <<-EOS.undent_________________________________________________________72
  #               Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
  #               eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
  #               minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
  #               ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
  #               voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
  #               sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
  #               mollit anim id est laborum.
  #               EOS
  alias undent_________________________________________________________72 undent
end