module DNote::StringExt
Extensions for String class. These methods are taken directly from Ruby Facets.
Public Instance Methods
indent(num)
click to toggle source
Indent left or right by num spaces. (This used to be called tab and aliased as indent
.)
CREDIT: Gavin Sinclair CREDIT: Trans
# File lib/dnote/core_ext.rb, line 14 def indent(num) if num >= 0 gsub(/^/, " " * num) else gsub(/^ {0,#{-num}}/, "") end end
tabset(num)
click to toggle source
# File lib/dnote/core_ext.rb, line 22 def tabset(num) i = lines.map do |line| line.strip.empty? ? nil : line.index(/\S/) end x = i.compact.min t = num - x.to_i t = 0 if t < 0 indent(t) end