Sorts self
in place.
Comparisons for the sort will be done using the <=>
operator or using an optional code block.
The block must implement a comparison between a
and b
and return an integer less than 0 when b
follows a
, 0
when a
and b
are equivalent, or an integer greater than 0 when a
follows b
.
See also Enumerable#sort_by
.
a = [ "d", "a", "e", "c", "b" ] a.sort! #=> ["a", "b", "c", "d", "e"] a.sort! { |x,y| y <=> x } #=> ["e", "d", "c", "b", "a"]
Returns a new array containing the items in self
for which the given block is not true
. The ordering of non-rejected elements is maintained.
See also Array#delete_if
If no block is given, an Enumerator
is returned instead.
Deletes every element of self
for which the block evaluates to true
, if no changes were made returns nil
.
The array may not be changed instantly every time the block is called.
See also Enumerable#reject
and Array#delete_if
.
If no block is given, an Enumerator
is returned instead.
Replaces the contents of self
with the contents of other_ary
, truncating or expanding if necessary.
a = [ "a", "b", "c", "d", "e" ] a.replace([ "x", "y", "z" ]) #=> ["x", "y", "z"] a #=> ["x", "y", "z"]
Creates a string representation of self
.
[ "a", "b", "c" ].to_s #=> "[\"a\", \"b\", \"c\"]"
Calculates the set of unambiguous abbreviations for the strings in self
.
require 'abbrev' %w{ car cone }.abbrev #=> {"car"=>"car", "ca"=>"car", "cone"=>"cone", "con"=>"cone", "co"=>"cone"}
The optional pattern
parameter is a pattern or a string. Only input strings that match the pattern or start with the string are included in the output hash.
%w{ fast boat day }.abbrev(/^.a/) #=> {"fast"=>"fast", "fas"=>"fast", "fa"=>"fast", "day"=>"day", "da"=>"day"} Abbrev.abbrev(%w{car box cone}, "ca") #=> {"car"=>"car", "ca"=>"car"}
See also Abbrev.abbrev
Returns a string containing the representation of big radix base (2 through 36).
12345654321.to_s #=> "12345654321" 12345654321.to_s(2) #=> "1011011111110110111011110000110001" 12345654321.to_s(8) #=> "133766736061" 12345654321.to_s(16) #=> "2dfdbbc31" 78546939656932.to_s(36) #=> "rubyrules"
Returns the remainder after dividing big by numeric.
-1234567890987654321.remainder(13731) #=> -6966 -1234567890987654321.remainder(13731.24) #=> -9906.22531493148
Converts big to a Float
. If big doesn’t fit in a Float
, the result is infinity.
Returns a complex object which denotes the given rectangular form.
Complex.rectangular(1, 2) #=> (1+2i)
Returns a complex object which denotes the given rectangular form.
Complex.rectangular(1, 2) #=> (1+2i)
Returns a complex object which denotes the given rectangular form.
Complex.rectangular(1, 2) #=> (1+2i)
Returns false.
Returns the value as a string.
Complex(2).to_s #=> "2+0i" Complex('-8/6').to_s #=> "-4/3+0i" Complex('1/2i').to_s #=> "0+1/2i" Complex(0, Float::INFINITY).to_s #=> "0+Infinity*i" Complex(Float::NAN, Float::NAN).to_s #=> "NaN+NaN*i"
Returns the value as an integer if possible (the imaginary part should be exactly zero).
Complex(1, 0).to_i #=> 1 Complex(1, 0.0).to_i # RangeError Complex(1, 2).to_i # RangeError
Returns the value as a float if possible (the imaginary part should be exactly zero).
Complex(1, 0).to_f #=> 1.0 Complex(1, 0.0).to_f # RangeError Complex(1, 2).to_f # RangeError
Returns the value as a rational if possible (the imaginary part should be exactly zero).
Complex(1, 0).to_r #=> (1/1) Complex(1, 0.0).to_r # RangeError Complex(1, 2).to_r # RangeError
See rationalize.
Returns zero as a complex.
Always returns the empty string.