Results for: "Pathname"

Foo::Bar, = baz ^^^^^^^^

def foo(**bar); end

^^^^^

def foo(**); end

^^

def foo(**nil); end

^^^^^

def foo(bar:); end

^^^^

Foo::Bar = 1 ^^^^^^^^^^^^

Foo::Foo, Bar::Bar = 1 ^^^^^^^^ ^^^^^^^^

Foo::Bar, = baz ^^^^^^^^

def foo(**bar); end

^^^^^

def foo(**); end

^^

def foo(**nil); end

^^^^^

def foo(bar:); end

^^^^

Returns elements from self in a new array; does not modify self.

The objects included in the returned array are the elements of self selected by the given specifiers, each of which must be a numeric index or a Range.

In brief:

a = ['a', 'b', 'c', 'd']

# Index specifiers.
a.values_at(2, 0, 2, 0)     # => ["c", "a", "c", "a"] # May repeat.
a.values_at(-4, -3, -2, -1) # => ["a", "b", "c", "d"] # Counts backwards if negative.
a.values_at(-50, 50)        # => [nil, nil]           # Outside of self.

# Range specifiers.
a.values_at(1..3)       # => ["b", "c", "d"] # From range.begin to range.end.
a.values_at(1...3)      # => ["b", "c"]      # End excluded.
a.values_at(3..1)       # => []              # No such elements.

a.values_at(-3..3)  # => ["b", "c", "d"]     # Negative range.begin counts backwards.
a.values_at(-50..3)                          # Raises RangeError.

a.values_at(1..-2)  # => ["b", "c"]          # Negative range.end counts backwards.
a.values_at(1..-50) # => []                  # No such elements.

# Mixture of specifiers.
a.values_at(2..3, 3, 0..1, 0) # => ["c", "d", "d", "a", "b", "a"]

With no specifiers given, returns a new empty array:

a = ['a', 'b', 'c', 'd']
a.values_at # => []

For each numeric specifier index, includes an element:

The given indexes may be in any order, and may repeat:

a.values_at(2, 0, 1, 0, 2) # => ["c", "a", "b", "a", "c"]

For each index that is out-of-range, includes nil:

a.values_at(4, -5) # => [nil, nil]

For each Range specifier range, includes elements according to range.begin and range.end:

The given ranges may be in any order and may repeat:

a.values_at(2..3, 0..1, 2..3) # => ["c", "d", "a", "b", "c", "d"]

The given specifiers may be any mixture of indexes and ranges:

a.values_at(3, 1..2, 0, 2..3) # => ["d", "b", "c", "a", "c", "d"]

Related: see Methods for Fetching.

Removes the element of self at the given index, which must be an integer-convertible object.

When index is non-negative, deletes the element at offset index:

a = [:foo, 'bar', 2]
a.delete_at(1) # => "bar"
a # => [:foo, 2]

When index is negative, counts backward from the end of the array:

a = [:foo, 'bar', 2]
a.delete_at(-2) # => "bar"
a # => [:foo, 2]

When index is out of range, returns nil.

a = [:foo, 'bar', 2]
a.delete_at(3)  # => nil
a.delete_at(-4) # => nil

Related: see Methods for Deleting.

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

See as_json.

Returns an array of the grapheme clusters in self (see Unicode Grapheme Cluster Boundaries):

s = "\u0061\u0308-pqr-\u0062\u0308-xyz-\u0063\u0308" # => "ä-pqr-b̈-xyz-c̈"
s.grapheme_clusters
# => ["ä", "-", "p", "q", "r", "-", "b̈", "-", "x", "y", "z", "-", "c̈"]

Returns whether self starts with any of the given string_or_regexp.

Matches patterns against the beginning of self. For each given string_or_regexp, the pattern is:

Returns true if any pattern matches the beginning, false otherwise:

'hello'.start_with?('hell')               # => true
'hello'.start_with?(/H/i)                 # => true
'hello'.start_with?('heaven', 'hell')     # => true
'hello'.start_with?('heaven', 'paradise') # => false
'тест'.start_with?('т')                   # => true
'こんにちは'.start_with?('こ')              # => true

Related: String#end_with?.

Returns whether self ends with any of the given strings.

Returns true if any given string matches the end, false otherwise:

'hello'.end_with?('ello')               #=> true
'hello'.end_with?('heaven', 'ello')     #=> true
'hello'.end_with?('heaven', 'paradise') #=> false
'тест'.end_with?('т')                   # => true
'こんにちは'.end_with?('は')              # => true

Related: String#start_with?.

Returns the next-larger representable Float.

These examples show the internally stored values (64-bit hexadecimal) for each Float f and for the corresponding f.next_float:

f = 0.0      # 0x0000000000000000
f.next_float # 0x0000000000000001

f = 0.01     # 0x3f847ae147ae147b
f.next_float # 0x3f847ae147ae147c

In the remaining examples here, the output is shown in the usual way (result to_s):

0.01.next_float    # => 0.010000000000000002
1.0.next_float     # => 1.0000000000000002
100.0.next_float   # => 100.00000000000001

f = 0.01
(0..3).each_with_index {|i| printf "%2d %-20a %s\n", i, f, f.to_s; f = f.next_float }

Output:

 0 0x1.47ae147ae147bp-7 0.01
 1 0x1.47ae147ae147cp-7 0.010000000000000002
 2 0x1.47ae147ae147dp-7 0.010000000000000004
 3 0x1.47ae147ae147ep-7 0.010000000000000005

f = 0.0; 100.times { f += 0.1 }
f                           # => 9.99999999999998       # should be 10.0 in the ideal world.
10-f                        # => 1.9539925233402755e-14 # the floating point error.
10.0.next_float-10          # => 1.7763568394002505e-15 # 1 ulp (unit in the last place).
(10-f)/(10.0.next_float-10) # => 11.0                   # the error is 11 ulp.
(10-f)/(10*Float::EPSILON)  # => 8.8                    # approximation of the above.
"%a" % 10                   # => "0x1.4p+3"
"%a" % f                    # => "0x1.3fffffffffff5p+3" # the last hex digit is 5.  16 - 5 = 11 ulp.

Related: Float#prev_float

Returns the next-smaller representable Float.

These examples show the internally stored values (64-bit hexadecimal) for each Float f and for the corresponding f.pev_float:

f = 5e-324   # 0x0000000000000001
f.prev_float # 0x0000000000000000

f = 0.01     # 0x3f847ae147ae147b
f.prev_float # 0x3f847ae147ae147a

In the remaining examples here, the output is shown in the usual way (result to_s):

0.01.prev_float   # => 0.009999999999999998
1.0.prev_float    # => 0.9999999999999999
100.0.prev_float  # => 99.99999999999999

f = 0.01
(0..3).each_with_index {|i| printf "%2d %-20a %s\n", i, f, f.to_s; f = f.prev_float }

Output:

0 0x1.47ae147ae147bp-7 0.01
1 0x1.47ae147ae147ap-7 0.009999999999999998
2 0x1.47ae147ae1479p-7 0.009999999999999997
3 0x1.47ae147ae1478p-7 0.009999999999999995

Related: Float#next_float.

Like backtrace, but returns each line of the execution stack as a Thread::Backtrace::Location. Accepts the same arguments as backtrace.

f = Fiber.new { Fiber.yield }
f.resume
loc = f.backtrace_locations.first
loc.label  #=> "yield"
loc.path   #=> "test.rb"
loc.lineno #=> 1

Returns default external encoding.

The default external encoding is used by default for strings created from the following locations:

While strings created from these locations will have this encoding, the encoding may not be valid. Be sure to check String#valid_encoding?.

File data written to disk will be transcoded to the default external encoding when written, if default_internal is not nil.

The default external encoding is initialized by the -E option. If -E isn’t set, it is initialized to UTF-8 on Windows and the locale on other operating systems.

Sets default external encoding. You should not set Encoding::default_external in ruby code as strings created before changing the value may have a different encoding from strings created after the value was changed., instead you should use ruby -E to invoke ruby with the correct default_external.

See Encoding::default_external for information on how the default external encoding is used.

Returns default internal encoding. Strings will be transcoded to the default internal encoding in the following places if the default internal encoding is not nil:

Additionally String#encode and String#encode! use the default internal encoding if no encoding is given.

The script encoding (__ENCODING__), not default_internal, is used as the encoding of created strings.

Encoding::default_internal is initialized with -E option or nil otherwise.

Sets default internal encoding or removes default internal encoding when passed nil. You should not set Encoding::default_internal in ruby code as strings created before changing the value may have a different encoding from strings created after the change. Instead you should use ruby -E to invoke ruby with the correct default_internal.

See Encoding::default_internal for information on how the default internal encoding is used.

Iterates the given block for each element with an index, which starts from offset. If no block is given, returns a new Enumerator that includes the index, starting from offset

offset

the starting index to use

Iterates the given block for each element with an arbitrary object, obj, and returns obj

If no block is given, returns a new Enumerator.

Example

to_three = Enumerator.new do |y|
  3.times do |x|
    y << x
  end
end

to_three_with_string = to_three.with_object("foo")
to_three_with_string.each do |x,string|
  puts "#{string}: #{x}"
end

# => foo: 0
# => foo: 1
# => foo: 2
Search took: 4ms  ·  Total Results: 2303