This is a Ruby tree! It shows every object from the Ruby Programming Language in a tree format.

fill

        # Array.fill

(from ruby core)
---
    array.fill(obj) -> self
    array.fill(obj, start) -> self
    array.fill(obj, start, length) -> self
    array.fill(obj, range) -> self
    array.fill {|index| ... } -> self
    array.fill(start) {|index| ... } -> self
    array.fill(start, length) {|index| ... } -> self
    array.fill(range) {|index| ... } -> self

---

Replaces specified elements in `self` with specified objects; returns
`self`.

With argument `obj` and no block given, replaces all elements with that
one object:
    a = ['a', 'b', 'c', 'd']
    a # => ["a", "b", "c", "d"]
    a.fill(:X) # => [:X, :X, :X, :X]

With arguments `obj` and Integer `start`, and no block given, replaces
elements based on the given start.

If `start` is in range (`0 <= start < array.size`), replaces all
elements from offset `start` through the end:
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, 2) # => ["a", "b", :X, :X]

If `start` is too large (`start >= array.size`), does nothing:
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, 4) # => ["a", "b", "c", "d"]
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, 5) # => ["a", "b", "c", "d"]

If `start` is negative, counts from the end (starting index is `start +
array.size`):
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, -2) # => ["a", "b", :X, :X]

If `start` is too small (less than and far from zero), replaces all
elements:
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, -6) # => [:X, :X, :X, :X]
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, -50) # => [:X, :X, :X, :X]

With arguments `obj`, Integer `start`, and Integer `length`, and no
block given, replaces elements based on the given `start` and `length`.

If `start` is in range, replaces `length` elements beginning at offset
`start`:
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, 1, 1) # => ["a", :X, "c", "d"]

If `start` is negative, counts from the end:
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, -2, 1) # => ["a", "b", :X, "d"]

If `start` is large (`start >= array.size`), extends `self` with `nil`:
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, 5, 0) # => ["a", "b", "c", "d", nil]
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, 5, 2) # => ["a", "b", "c", "d", nil, :X, :X]

If `length` is zero or negative, replaces no elements:
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, 1, 0) # => ["a", "b", "c", "d"]
    a.fill(:X, 1, -1) # => ["a", "b", "c", "d"]

With arguments `obj` and Range `range`, and no block given, replaces
elements based on the given range.

If the range is positive and ascending (`0 < range.begin <= range.end`),
replaces elements from `range.begin` to `range.end`:
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, (1..1)) # => ["a", :X, "c", "d"]

If `range.first` is negative, replaces no elements:
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, (-1..1)) # => ["a", "b", "c", "d"]

If `range.last` is negative, counts from the end:
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, (0..-2)) # => [:X, :X, :X, "d"]
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, (1..-2)) # => ["a", :X, :X, "d"]

If `range.last` and `range.last` are both negative, both count from the
end of the array:
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, (-1..-1)) # => ["a", "b", "c", :X]
    a = ['a', 'b', 'c', 'd']
    a.fill(:X, (-2..-2)) # => ["a", "b", :X, "d"]

With no arguments and a block given, calls the block with each index;
replaces the corresponding element with the block's return value:
    a = ['a', 'b', 'c', 'd']
    a.fill { |index| "new_#{index}" } # => ["new_0", "new_1", "new_2", "new_3"]

With argument `start` and a block given, calls the block with each index
from offset `start` to the end; replaces the corresponding element with
the block's return value:

If start is in range (`0 <= start < array.size`), replaces from offset
`start` to the end:
    a = ['a', 'b', 'c', 'd']
    a.fill(1) { |index| "new_#{index}" } # => ["a", "new_1", "new_2", "new_3"]

If `start` is too large(`start >= array.size`), does nothing:
    a = ['a', 'b', 'c', 'd']
    a.fill(4) { |index| fail 'Cannot happen' } # => ["a", "b", "c", "d"]
    a = ['a', 'b', 'c', 'd']
    a.fill(4) { |index| fail 'Cannot happen' } # => ["a", "b", "c", "d"]

If `start` is negative, counts from the end:
    a = ['a', 'b', 'c', 'd']
    a.fill(-2) { |index| "new_#{index}" } # => ["a", "b", "new_2", "new_3"]

If start is too small (`start <= -array.size`, replaces all elements:
    a = ['a', 'b', 'c', 'd']
    a.fill(-6) { |index| "new_#{index}" } # => ["new_0", "new_1", "new_2", "new_3"]
    a = ['a', 'b', 'c', 'd']
    a.fill(-50) { |index| "new_#{index}" } # => ["new_0", "new_1", "new_2", "new_3"]

With arguments `start` and `length`, and a block given, calls the block
for each index specified by start length; replaces the corresponding
element with the block's return value.

If `start` is in range, replaces `length` elements beginning at offset
`start`:
    a = ['a', 'b', 'c', 'd']
    a.fill(1, 1) { |index| "new_#{index}" } # => ["a", "new_1", "c", "d"]

If start is negative, counts from the end:
    a = ['a', 'b', 'c', 'd']
    a.fill(-2, 1) { |index| "new_#{index}" } # => ["a", "b", "new_2", "d"]

If `start` is large (`start >= array.size`), extends `self` with `nil`:
    a = ['a', 'b', 'c', 'd']
    a.fill(5, 0) { |index| "new_#{index}" } # => ["a", "b", "c", "d", nil]
    a = ['a', 'b', 'c', 'd']
    a.fill(5, 2) { |index| "new_#{index}" } # => ["a", "b", "c", "d", nil, "new_5", "new_6"]

If `length` is zero or less, replaces no elements:
    a = ['a', 'b', 'c', 'd']
    a.fill(1, 0) { |index| "new_#{index}" } # => ["a", "b", "c", "d"]
    a.fill(1, -1) { |index| "new_#{index}" } # => ["a", "b", "c", "d"]

With arguments `obj` and `range`, and a block given, calls the block
with each index in the given range; replaces the corresponding element
with the block's return value.

If the range is positive and ascending (`range 0 < range.begin <=
range.end`, replaces elements from `range.begin` to `range.end`:
    a = ['a', 'b', 'c', 'd']
    a.fill(1..1) { |index| "new_#{index}" } # => ["a", "new_1", "c", "d"]

If `range.first` is negative, does nothing:
    a = ['a', 'b', 'c', 'd']
    a.fill(-1..1) { |index| fail 'Cannot happen' } # => ["a", "b", "c", "d"]

If `range.last` is negative, counts from the end:
    a = ['a', 'b', 'c', 'd']
    a.fill(0..-2) { |index| "new_#{index}" } # => ["new_0", "new_1", "new_2", "d"]
    a = ['a', 'b', 'c', 'd']
    a.fill(1..-2) { |index| "new_#{index}" } # => ["a", "new_1", "new_2", "d"]

If `range.first` and `range.last` are both negative, both count from the
end:
    a = ['a', 'b', 'c', 'd']
    a.fill(-1..-1) { |index| "new_#{index}" } # => ["a", "b", "c", "new_3"]
    a = ['a', 'b', 'c', 'd']
    a.fill(-2..-2) { |index| "new_#{index}" } # => ["a", "b", "new_2", "d"]



      

This is MURDOC! A Ruby documentation browser inspired by Smalltalk-80. It allows you to learn about Ruby by browsing through its class hierarchies, and see any of its methods.