module Gemmy::Patches::StringPatch::InstanceMethods::ExpandTabs
Public Instance Methods
expand_tabs(n=8)
click to toggle source
turns tabs to spaces
# File lib/gemmy/patches/string_patch.rb, line 203 def expand_tabs(n=8) n = n.to_int raise ArgumentError, "n must be >= 0" if n < 0 return gsub(/\t/, "") if n == 0 return gsub(/\t/, " ") if n == 1 str = self.dup while str.gsub!(/^([^\t\n]*)(\t+)/) { |f| val = ( n * $2.size - ($1.size % n) ) $1 << (' ' * val) } end str end