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

one?

        # Array.one?

(from ruby core)
---
    array.one? -> true or false
    array.one? {|element| ... } -> true or false
    array.one?(obj) -> true or false

---

Returns `true` if exactly one element of `self` meets a given criterion.

With no block given and no argument, returns `true` if `self` has
exactly one truthy element, `false` otherwise:
    [nil, 0].one? # => true
    [0, 0].one? # => false
    [nil, nil].one? # => false
    [].one? # => false

With a block given and no argument, calls the block with each element in
`self`; returns `true` if the block a truthy value for exactly one
element, `false` otherwise:
    [0, 1, 2].one? {|element| element > 0 } # => false
    [0, 1, 2].one? {|element| element > 1 } # => true
    [0, 1, 2].one? {|element| element > 2 } # => false

If argument `obj` is given, returns `true` if `obj.===` exactly one
element, `false` otherwise:
    [0, 1, 2].one?(0) # => true
    [0, 0, 1].one?(0) # => false
    [1, 1, 2].one?(0) # => false
    ['food', 'drink'].one?(/bar/) # => false
    ['food', 'drink'].one?(/foo/) # => true
    [].one?(/foo/) # => false

Related: Enumerable#one?



      

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.