class String

Public Instance Methods

String#iseuc → true or false click to toggle source

Returns whether self‘s encoding is EUC-JP or not.

# File rake/lib/kconv.rb, line 263
def iseuc;    Kconv.iseuc(self) end
String#isjis → true or false click to toggle source

Returns whether self‘s encoding is ISO-2022-JP or not.

# File rake/lib/kconv.rb, line 275
def isjis;    Kconv.isjis(self) end
String#issjis → true or false click to toggle source

Returns whether self‘s encoding is Shift_JIS or not.

# File rake/lib/kconv.rb, line 269
def issjis;   Kconv.issjis(self) end
String#isutf8 → true or false click to toggle source

Returns whether self‘s encoding is UTF-8 or not.

# File rake/lib/kconv.rb, line 281
def isutf8;   Kconv.isutf8(self) end
String#kconv(to_enc, from_enc) click to toggle source

Convert self to to_enc. to_enc and from_enc are given as constants of Kconv or Encoding objects.

# File rake/lib/kconv.rb, line 204
def kconv(to_enc, from_enc=nil)
  from_enc = self.encoding if !from_enc && self.encoding != Encoding.list[0]
  Kconv::kconv(self, to_enc, from_enc)
end
parse_csv(options = Hash.new) click to toggle source

Equivalent to CSV::parse_line(self, options).

# File rake/lib/csv.rb, line 2352
def parse_csv(options = Hash.new)
  CSV.parse_line(self, options)
end
String#toeuc → string click to toggle source

Convert self to EUC-JP

# File rake/lib/kconv.rb, line 223
def toeuc; Kconv.toeuc(self) end
String#tojis → string click to toggle source

Convert self to ISO-2022-JP

# File rake/lib/kconv.rb, line 217
def tojis; Kconv.tojis(self) end
String#tolocale → string click to toggle source

Convert self to locale encoding

# File rake/lib/kconv.rb, line 253
def tolocale; Kconv.tolocale(self) end
String#tosjis → string click to toggle source

Convert self to Shift_JIS

# File rake/lib/kconv.rb, line 229
def tosjis; Kconv.tosjis(self) end
String#toutf16 → string click to toggle source

Convert self to UTF-16

# File rake/lib/kconv.rb, line 241
def toutf16; Kconv.toutf16(self) end
String#toutf32 → string click to toggle source

Convert self to UTF-32

# File rake/lib/kconv.rb, line 247
def toutf32; Kconv.toutf32(self) end
String#toutf8 → string click to toggle source

Convert self to UTF-8

# File rake/lib/kconv.rb, line 235
def toutf8; Kconv.toutf8(self) end

scanf

↑ top

Public Instance Methods

block_scanf(fstr) { |current_match| ... } click to toggle source

Scans the current string until the match is exhausted yielding each match as it is encountered in the string. A block is not necessary as the results will simply be aggregated into the final array.

"123 456".block_scanf("%d")
# => [123, 456]

If a block is given, the value from that is returned from the yield is added to an output array.

"123 456".block_scanf("%d) do |digit,| # the ',' unpacks the Array
  digit + 100
end
# => [223, 556]

See Scanf for details on creating a format string.

You will need to require ‘scanf’ to use #block_scanf

# File rake/lib/scanf.rb, line 748
def block_scanf(fstr,&b) #:yield: current_match
  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
scanf(fstr) { |current_match| ... } click to toggle source

Scans the current string. If a block is given, it functions exactly like block_scanf.

arr = "123 456".scanf("%d%d")
# => [123, 456]

require 'pp'

"this 123 read that 456 other".scanf("%s%d%s") {|m| pp m}

# ["this", 123, "read"]
# ["that", 456, "other"]
# => [["this", 123, "read"], ["that", 456, "other"]]

See Scanf for details on creating a format string.

You will need to require ‘scanf’ to use #scanf

# File rake/lib/scanf.rb, line 715
def scanf(fstr,&b) #:yield: current_match
  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
shellescape → string click to toggle source

Escapes str so that it can be safely used in a Bourne shell command line. See Shellwords.shellescape for details.

# File rake/lib/shellwords.rb, line 136
def shellescape
  Shellwords.escape(self)
end
shellsplit → array click to toggle source

Splits str into an array of tokens in the same way the UNIX Bourne shell does. See Shellwords.shellsplit for details.

# File rake/lib/shellwords.rb, line 127
def shellsplit
  Shellwords.split(self)
end