Returns self.
Returns self.
If a numeric
is the same type as num
, returns an array containing numeric
and num
. Otherwise, returns an array with both a numeric
and num
represented as Float
objects.
This coercion mechanism is used by Ruby to handle mixed-type numeric operations: it is intended to find a compatible common type between the two operands of the operator.
1.coerce(2.5) #=> [2.5, 1.0] 1.2.coerce(3) #=> [3.0, 1.2] 1.coerce(2) #=> [2, 1]
Returns true
if num
is an Integer
(including Fixnum
and Bignum
).
(1.0).integer? #=> false (1).integer? #=> true
Returns true
if num
has a zero value.
Returns true
if num
is greater than 0.
Returns true
if num
is less than 0.
Returns the numerator.
Returns whether self
‘s encoding is EUC-JP or not.
Case-insensitive version of String#<=>
.
"abcdef".casecmp("abcde") #=> 1 "aBcDeF".casecmp("abcdef") #=> 0 "abcdef".casecmp("abcdefg") #=> -1 "abcdef".casecmp("ABCDEF") #=> 0
Returns true
if str has a length of zero.
"hello".empty? #=> false " ".empty? #=> false "".empty? #=> true
Iterates through successive values, starting at str and ending at other_str inclusive, passing each value in turn to the block. The String#succ
method is used to generate each value. If optional second argument exclusive is omitted or is false, the last value will be included; otherwise it will be excluded.
If no block is given, an enumerator is returned instead.
"a8".upto("b6") {|s| print s, ' ' } for s in "a8".."b6" print s, ' ' end
produces:
a8 a9 b0 b1 b2 b3 b4 b5 b6 a8 a9 b0 b1 b2 b3 b4 b5 b6
If str and other_str contains only ascii numeric characters, both are recognized as decimal numbers. In addition, the width of string (e.g. leading zeros) is handled appropriately.
"9".upto("11").to_a #=> ["9", "10", "11"] "25".upto("5").to_a #=> [] "07".upto("11").to_a #=> ["07", "08", "09", "10", "11"]
modifies the indexth byte as integer.
Returns a copy of str with all lowercase letters replaced with their uppercase counterparts. The operation is locale insensitive—only characters “a” to “z” are affected. Note: case replacement is effective only in ASCII region.
"hEllO".upcase #=> "HELLO"
Returns a copy of str with all uppercase letters replaced with their lowercase counterparts. The operation is locale insensitive—only characters “A” to “Z” are affected. Note: case replacement is effective only in ASCII region.
"hEllO".downcase #=> "hello"
Returns a copy of str with uppercase alphabetic characters converted to lowercase and lowercase characters converted to uppercase. Note: case conversion is effective only in ASCII region.
"Hello".swapcase #=> "hELLO" "cYbEr_PuNk11".swapcase #=> "CyBeR_pUnK11"
Upcases the contents of str, returning nil
if no changes were made. Note: case replacement is effective only in ASCII region.
Downcases the contents of str, returning nil
if no changes were made. Note: case replacement is effective only in ASCII region.
Equivalent to String#swapcase
, but modifies the receiver in place, returning str, or nil
if no changes were made. Note: case conversion is effective only in ASCII region.
Append—Concatenates the given object to str. If the object is a Integer
, it is considered as a codepoint, and is converted to a character before concatenation.
a = "hello " a << "world" #=> "hello world" a.concat(33) #=> "hello world!"
Applies a one-way cryptographic hash to str by invoking the standard library function crypt(3)
with the given salt string. While the format and the result are system and implementation dependent, using a salt matching the regular expression \A[a-zA-Z0-9./]{2}
should be valid and safe on any platform, in which only the first two characters are significant.
This method is for use in system specific scripts, so if you want a cross-platform hash function consider using Digest
or OpenSSL
instead.
Returns the Symbol
corresponding to str, creating the symbol if it did not previously exist. See Symbol#id2name
.
"Koala".intern #=> :Koala s = 'cat'.to_sym #=> :cat s == :cat #=> true s = '@cat'.to_sym #=> :@cat s == :@cat #=> true
This can also be used to create symbols that cannot be represented using the :xxx
notation.
'cat and dog'.to_sym #=> :"cat and dog"