Produces a shallow copy of obj—the instance variables of obj are copied, but not the objects they reference. clone
copies the frozen (unless :freeze keyword argument is given with a false value) and tainted state of obj. See also the discussion under Object#dup
.
class Klass attr_accessor :str end s1 = Klass.new #=> #<Klass:0x401b3a38> s1.str = "Hello" #=> "Hello" s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello"> s2.str[1,4] = "i" #=> "i" s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">" s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
This method may have class-specific behavior. If so, that behavior will be documented under the #initialize_copy
method of the class.
Returns obj.
string = 'my string' #=> "my string" string.itself.object_id == string.object_id #=> true
provides a unified clone
operation, for REXML::XPathParser
to use across multiple Object
types
Returns the absolute value of int
.
-12345.abs #=> 12345 12345.abs #=> 12345 -1234567890987654321.abs #=> 1234567890987654321
Returns the array including the digits extracted by place-value notation with radix base
of int
.
base
should be greater than or equal to 2.
12345.digits #=> [5, 4, 3, 2, 1] 12345.digits(7) #=> [4, 6, 6, 0, 5] 12345.digits(100) #=> [45, 23, 1] -12345.digits(7) #=> Math::DomainError
Returns a complex object which denotes the given rectangular form.
Complex.rectangular(1, 2) #=> (1+2i)
Returns a complex object which denotes the given polar form.
Complex.polar(3, 0) #=> (3.0+0.0i) Complex.polar(3, Math::PI/2) #=> (1.836909530733566e-16+3.0i) Complex.polar(3, Math::PI) #=> (-3.0+3.673819061467132e-16i) Complex.polar(3, -Math::PI/2) #=> (1.836909530733566e-16-3.0i)
Returns the imaginary part.
Complex(7).imaginary #=> 0 Complex(9, -4).imaginary #=> -4
Returns the absolute part of its polar form.
Complex(-1).abs #=> 1 Complex(3.0, -4.0).abs #=> 5.0
Returns the angle part of its polar form.
Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966
Returns an array; [cmp.abs, cmp.arg].
Complex(1, 2).polar #=> [2.23606797749979, 1.1071487177940904]
Returns true
if cmp
‘s magnitude is finite number, oterwise returns false
.
Returns values corresponding to the value of cmp
‘s magnitude:
finite
nil
+Infinity
+1
For example: (1+1i).infinite? #=> nil (Float::INFINITY + 1i).infinite? #=> 1
Returns zero.
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.
Returns the absolute value of num
.
12.abs #=> 12 (-34.56).abs #=> 34.56 -34.56.abs #=> 34.56
Numeric#magnitude
is an alias of Numeric#abs
.
Returns self
if num
is not zero, nil
otherwise.
This behavior is useful when chaining comparisons:
a = %w( z Bb bB bb BB a aA Aa AA A ) b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b } b #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
Return true if num
is finite number, oterwise returns false.