Sha256: 537125181a91df2905755462068b54c67e0ddbd8b0d21c28c219cd8faf015e6d
Contents?: true
Size: 517 Bytes
Versions: 4
Compression:
Stored size: 517 Bytes
Contents
# frozen_string_literal: true # https://makandracards.com/makandra/6087-ruby-indent-a-string String.class_eval do def indent(count, char = ' ', skip_first_line: false) gsub(/([^\n]*)(\n|$)/) do |_match| last_iteration = (Regexp.last_match(1) == '' && Regexp.last_match(2) == '') line = String.new line << (char * count) unless last_iteration || skip_first_line line << Regexp.last_match(1) line << Regexp.last_match(2) skip_first_line = false line end end end
Version data entries
4 entries across 4 versions & 1 rubygems