Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/rake.rb,
lib/csv.rb,
lib/mkmf.rb,
lib/scanf.rb,
lib/shellwords.rb
Overview
User defined methods to be added to String.
Instance Method Summary (collapse)
- - (Object) block_scanf(fstr, &b)
-
- (Object) parse_csv(options = Hash.new)
Equivalent to CSV::parse_line(self, options).
-
- (Object) quote
Wraps a string in escaped quotes if it contains whitespace.
- - (Object) scanf(fstr, &b)
-
- (Object) shellescape
call-seq:.
-
- (Object) shellsplit
call-seq:.
-
- (Object) tr_cpp
Generates a string used as cpp macro name.
Instance Method Details
- (Object) block_scanf(fstr, &b)
685 686 687 688 689 690 691 692 693 694 695 |
# File 'lib/scanf.rb', line 685 def block_scanf(fstr,&b) fs = Scanf::FormatString.new(fstr) str = self.dup final = [] begin current = str.scanf(fs) final.push(yield(current)) unless current.empty? str = fs.string_left end until current.empty? || str.empty? return final end |
- (Object) parse_csv(options = Hash.new)
Equivalent to CSV::parse_line(self, options).
2336 2337 2338 |
# File 'lib/csv.rb', line 2336 def parse_csv( = Hash.new) CSV.parse_line(self, ) end |
- (Object) quote
Wraps a string in escaped quotes if it contains whitespace.
181 182 183 |
# File 'lib/mkmf.rb', line 181 def quote /\s/ =~ self ? "\"#{self}\"" : "#{self}" end |
- (Object) scanf(fstr, &b)
671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'lib/scanf.rb', line 671 def scanf(fstr,&b) if b block_scanf(fstr,&b) else fs = if fstr.is_a? Scanf::FormatString fstr else Scanf::FormatString.new(fstr) end fs.match(self) end end |
- (Object) shellescape
call-seq:
str.shellescape => string
Escapes str so that it can be safely used in a Bourne shell command line. See Shellwords::shellescape for details.
139 140 141 |
# File 'lib/shellwords.rb', line 139 def shellescape Shellwords.escape(self) end |
- (Object) shellsplit
call-seq:
str.shellsplit => array
Splits str into an array of tokens in the same way the UNIX Bourne shell does. See Shellwords::shellsplit for details.
128 129 130 |
# File 'lib/shellwords.rb', line 128 def shellsplit Shellwords.split(self) end |
- (Object) tr_cpp
Generates a string used as cpp macro name.
186 187 188 |
# File 'lib/mkmf.rb', line 186 def tr_cpp strip.upcase.tr_s("^A-Z0-9_", "_") end |