Module: CoreEx::String
- Included in:
- String
- Defined in:
- lib/core_ex/string.rb
Instance Method Summary collapse
-
#head_cut!(sep = '\|') ⇒ Object
Provide an helper to cut strings.
- #import! ⇒ Object
- #rec_fold(init, &block) ⇒ Object
- #to_path ⇒ Object
- #to_proc ⇒ Object
- #to_uri ⇒ Object (also: #to_url)
- #width ⇒ Object
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_path ⇒ Object
33 34 35 |
# File 'lib/core_ex/string.rb', line 33 def to_path ::Pathname.new(self) end |
#to_proc ⇒ Object
42 43 44 |
# File 'lib/core_ex/string.rb', line 42 def to_proc DumpableProc.new(self) end |
#to_uri ⇒ Object Also known as: to_url
37 38 39 |
# File 'lib/core_ex/string.rb', line 37 def to_uri URI.parse(self) end |
#width ⇒ Object
54 55 56 |
# File 'lib/core_ex/string.rb', line 54 def width size + count("\t") * 7 # TABWIDTH(8) - 1 end |