@@foo = 1 ^^^^^^^^^
@@foo, @@bar = 1 ^^^^^ ^^^^^
@@foo, = bar ^^^^^
Foo += bar ^^^^^^^^^^^
Foo &&= bar ^^^^^^^^^^^^
Foo ||= bar ^^^^^^^^^^^^
$foo = 1 ^^^^^^^^
$foo, $bar = 1 ^^^^ ^^^^
@foo = 1 ^^^^^^^^
@foo, @bar = 1 ^^^^ ^^^^
def foo(**bar); end
^^^^^
def foo(**); end
^^
foo = 1 ^^^^^^^
foo, bar = 1 ^^^ ^^^
def foo(bar:); end
^^^^
Returns self
.
With a block given, sorts the elements of self
in place; returns self.
Calls the block with each successive element; sorts elements based on the values returned from the block:
a = ['aaaa', 'bbb', 'cc', 'd'] a.sort_by! {|element| element.size } a # => ["d", "cc", "bbb", "aaaa"]
For duplicate values returned by the block, the ordering is indeterminate, and may be unstable.
With no block given, returns a new Enumerator
.
Related: see Methods for Assigning.
Returns the integer index of the element from self
found by a binary search, or nil
if the search found no suitable element.
See Binary Searching.
Related: see Methods for Fetching.
Returns the number of bits of the value of self
, which is the bit position of the highest-order bit that is different from the sign bit (where the least significant bit has bit position 1). If there is no such bit (zero or minus one), returns zero.
This method returns ceil(log2(self < 0 ? -self : self + 1))
>.
(-2**1000-1).bit_length # => 1001 (-2**1000).bit_length # => 1000 (-2**1000+1).bit_length # => 1000 (-2**12-1).bit_length # => 13 (-2**12).bit_length # => 12 (-2**12+1).bit_length # => 12 -0x101.bit_length # => 9 -0x100.bit_length # => 8 -0xff.bit_length # => 8 -2.bit_length # => 1 -1.bit_length # => 0 0.bit_length # => 0 1.bit_length # => 1 0xff.bit_length # => 8 0x100.bit_length # => 9 (2**12-1).bit_length # => 12 (2**12).bit_length # => 13 (2**12+1).bit_length # => 13 (2**1000-1).bit_length # => 1000 (2**1000).bit_length # => 1001 (2**1000+1).bit_length # => 1001
For Integer n, this method can be used to detect overflow in Array#pack
:
if n.bit_length < 32 [n].pack('l') # No overflow. else raise 'Overflow' end