Results for: "String#[]"

Returns a left-justified copy of self.

If integer argument size is greater than the size (in characters) of self, returns a new string of length size that is a copy of self, left justified and padded on the right with pad_string:

'hello'.ljust(10)       # => "hello     "
'  hello'.ljust(10)     # => "  hello   "
'hello'.ljust(10, 'ab') # => "helloababa"
'тест'.ljust(10)        # => "тест      "
'こんにちは'.ljust(10)    # => "こんにちは     "

If size is not greater than the size of self, returns a copy of self:

'hello'.ljust(5)  # => "hello"
'hello'.ljust(1)  # => "hello"

Related: String#rjust, String#center.

Returns a right-justified copy of self.

If integer argument size is greater than the size (in characters) of self, returns a new string of length size that is a copy of self, right justified and padded on the left with pad_string:

'hello'.rjust(10)       # => "     hello"
'hello  '.rjust(10)     # => "   hello  "
'hello'.rjust(10, 'ab') # => "ababahello"
'тест'.rjust(10)        # => "      тест"
'こんにちは'.rjust(10)    # => "     こんにちは"

If size is not greater than the size of self, returns a copy of self:

'hello'.rjust(5, 'ab')  # => "hello"
'hello'.rjust(1, 'ab')  # => "hello"

Related: String#ljust, String#center.

Returns a copy of self with each character specified by string selector translated to the corresponding character in string replacements. The correspondence is positional:

Example:

'hello'.tr('el', 'ip') #=> "hippo"

If replacements is shorter than selector, it is implicitly padded with its own last character:

'hello'.tr('aeiou', '-')   # => "h-ll-"
'hello'.tr('aeiou', 'AA-') # => "hAll-"

Arguments selector and replacements must be valid character selectors (see Character Selectors), and may use any of its valid forms, including negation, ranges, and escaping:

# Negation.
'hello'.tr('^aeiou', '-') # => "-e--o"
# Ranges.
'ibm'.tr('b-z', 'a-z') # => "hal"
# Escapes.
'hel^lo'.tr('\^aeiou', '-')     # => "h-l-l-"    # Escaped leading caret.
'i-b-m'.tr('b\-z', 'a-z')       # => "ibabm"     # Escaped embedded hyphen.
'foo\\bar'.tr('ab\\', 'XYZ')    # => "fooZYXr"   # Escaped backslash.

Like String#tr, but modifies self in place. Returns self if any changes were made, nil otherwise.

USE OF RIPPER LIBRARY ONLY.

Strips up to width leading whitespaces from input, and returns the stripped column width.

USE OF RIPPER LIBRARY ONLY.

Strips up to width leading whitespaces from input, and returns the stripped column width.

Returns a string containing the IP address representation in canonical form.

No documentation available

Returns a copy of self transcoded as determined by dst_encoding. By default, raises an exception if self contains an invalid byte or a character not defined in dst_encoding; that behavior may be modified by encoding options; see below.

With no arguments:

With only argument dst_encoding given, uses that encoding:

s = "Ruby\x99".force_encoding('Windows-1252')
s.encoding            # => #<Encoding:Windows-1252>
t = s.encode('UTF-8') # => "Ruby™"
t.encoding            # => #<Encoding:UTF-8>

With arguments dst_encoding and src_encoding given, interprets self using src_encoding, encodes the new string using dst_encoding:

s = "Ruby\x99"
t = s.encode('UTF-8', 'Windows-1252') # => "Ruby™"
t.encoding                            # => #<Encoding:UTF-8>

Optional keyword arguments enc_opts specify encoding options; see Encoding Options.

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

Convert self to ISO-2022-JP

Convert self to EUC-JP

Convert self to Shift_JIS

Convert self to UTF-8

Convert self to UTF-16

Convert self to UTF-32

Convert self to locale encoding

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

Returns whether self‘s encoding is Shift_JIS or not.

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

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

Splits str into an array of tokens in the same way the UNIX Bourne shell does.

See Shellwords.shellsplit for details.

Escapes str so that it can be safely used in a Bourne shell command line.

See Shellwords.shellescape for details.

Extracts data from self, forming objects that become the elements of a new array; returns that array. See Packed Data.

Like String#unpack, but unpacks and returns only the first extracted object. See Packed Data.

Search took: 3ms  ·  Total Results: 2816