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

repeated_permutation

        # Array.repeated_permutation

(from ruby core)
---
    array.repeated_permutation(n) {|permutation| ... } -> self
    array.repeated_permutation(n) -> new_enumerator

---

Calls the block with each repeated permutation of length `n` of the
elements of `self`; each permutation is an Array; returns `self`. The
order of the permutations is indeterminate.

When a block and a positive Integer argument `n` are given, calls the
block with each `n`-tuple repeated permutation of the elements of
`self`. The number of permutations is `self.size**n`.

`n` = 1:
    a = [0, 1, 2]
    a.repeated_permutation(1) {|permutation| p permutation }

Output:
    [0]
    [1]
    [2]

`n` = 2:
    a.repeated_permutation(2) {|permutation| p permutation }

Output:
    [0, 0]
    [0, 1]
    [0, 2]
    [1, 0]
    [1, 1]
    [1, 2]
    [2, 0]
    [2, 1]
    [2, 2]

If `n` is zero, calls the block once with an empty Array.

If `n` is negative, does not call the block:
    a.repeated_permutation(-1) {|permutation| fail 'Cannot happen' }

Returns a new Enumerator if no block given:
    a = [0, 1, 2]
    a.repeated_permutation(2) # => #<Enumerator: [0, 1, 2]:permutation(2)>

Using Enumerators, it's convenient to show the permutations and counts
for some values of `n`:
    e = a.repeated_permutation(0)
    e.size # => 1
    e.to_a # => [[]]
    e = a.repeated_permutation(1)
    e.size # => 3
    e.to_a # => [[0], [1], [2]]
    e = a.repeated_permutation(2)
    e.size # => 9
    e.to_a # => [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]



      

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.