Sha256: 5f13093c122ad84b0099209b8eb51c075228343856c95671cc5cd5ab89f7f6f9
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
class Regex # Extensions for String class. # These methods are taken directly from Ruby Facets. # module String # Provides a margin controlled string. # # x = %Q{ # | This # | is # | margin controlled! # }.margin # # # NOTE: This may still need a bit of tweaking. # # CREDIT: Trans def margin(n=0) #d = /\A.*\n\s*(.)/.match( self )[1] #d = /\A\s*(.)/.match( self)[1] unless d d = ((/\A.*\n\s*(.)/.match(self)) || (/\A\s*(.)/.match(self)))[1] return '' unless d if n == 0 gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, '') else gsub(/\n\s*\Z/,'').gsub(/^\s*[#{d}]/, ' ' * n) end end # Preserves relative tabbing. # The first non-empty line ends up with n spaces before nonspace. # # CREDIT: Gavin Sinclair def tabto(n) if self =~ /^( *)\S/ indent(n - $1.length) else self end end # Indent left or right by n spaces. # (This used to be called #tab and aliased as #indent.) # # CREDIT: Gavin Sinclair # CREDIT: Trans def indent(n) if n >= 0 gsub(/^/, ' ' * n) else gsub(/^ {0,#{-n}}/, "") end end end class ::String #:nodoc: include Regex::String end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
regex-1.0.0 | lib/regex/string.rb |