Module: CoreEx::String

Included in:
String
Defined in:
lib/core_ex/string.rb

Instance Method Summary collapse

Instance Method Details

#head_cut!(sep = '\|') ⇒ Object

Provide an helper to cut strings.

Example:

puts "
  |        A very complex
  |            string
  |  with a specific indentation.
  |
  |I prefer that instead of a HERE doc
  |  because I keep my indentation.
  |".head_cut!


24
25
26
27
# File 'lib/core_ex/string.rb', line 24

def head_cut! ( sep='\|' )
  gsub!(/^\s*#{sep}/, '')
  self
end

#import!Object



29
30
31
# File 'lib/core_ex/string.rb', line 29

def import!
  to_path.import!
end

#rec_fold(init, &block) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/core_ex/string.rb', line 46

def rec_fold ( init, &block )
  if include? "\n"
    super
  else
    block[init, self]
  end
end

#to_pathObject



33
34
35
# File 'lib/core_ex/string.rb', line 33

def to_path
  ::Pathname.new(self)
end

#to_procObject



42
43
44
# File 'lib/core_ex/string.rb', line 42

def to_proc
  DumpableProc.new(self)
end

#to_uriObject Also known as: to_url



37
38
39
# File 'lib/core_ex/string.rb', line 37

def to_uri
  URI.parse(self)
end

#widthObject



54
55
56
# File 'lib/core_ex/string.rb', line 54

def width
  size + count("\t") * 7 # TABWIDTH(8) - 1
end