Returns an array; [cmp.abs, cmp.arg].
Complex(1, 2).polar #=> [2.23606797749979, 1.1071487177940904]
Returns the numerator.
1 2 3+4i <- numerator - + -i -> ---- 2 3 6 <- denominator c = Complex('1/2+2/3i') #=> ((1/2)+(2/3)*i) n = c.numerator #=> (3+4i) d = c.denominator #=> 6 n / d #=> ((1/2)+(2/3)*i) Complex(Rational(n.real, d), Rational(n.imag, d)) #=> ((1/2)+(2/3)*i)
See denominator.
Returns zero.
Returns 0 if the value is positive, pi otherwise.
Returns 0 if the value is positive, pi otherwise.
Returns an array; [num, 0].
Returns an array; [num.abs, num.arg].
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
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#<=>
. Currently, case-insensitivity only works on characters A-Z/a-z, not all of Unicode. This is different from casecmp?
.
"abcdef".casecmp("abcde") #=> 1 "aBcDeF".casecmp("abcdef") #=> 0 "abcdef".casecmp("abcdefg") #=> -1 "abcdef".casecmp("ABCDEF") #=> 0
Returns true if str and other_other_str are equal after Unicode case folding, false if they are not equal, and nil if other_str is not a string.
"abcdef".casecmp?("abcde") #=> false "aBcDeF".casecmp?("abcdef") #=> true "abcdef".casecmp?("abcdefg") #=> false "abcdef".casecmp?("ABCDEF") #=> true "\u{e4 f6 fc}".casecmp?("\u{c4 d6 dc}") #=> true
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"]