Method: Hash#select!

Defined in:
hash.c

#select! {|key, value| ... } ⇒ Hash? #select!Object #filter! {|key, value| ... } ⇒ Hash? #filter!Object

Equivalent to Hash#keep_if, but returns nil if no changes were made.

Hash#filter! is an alias for Hash#select!.

Overloads:

  • #select! {|key, value| ... } ⇒ Hash?

    Yields:

    Returns:

  • #filter! {|key, value| ... } ⇒ Hash?

    Yields:

    Returns:



2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
# File 'hash.c', line 2656

VALUE
rb_hash_select_bang(VALUE hash)
{
    st_index_t n;

    RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
    rb_hash_modify_check(hash);
    n = RHASH_SIZE(hash);
    if (!n) return Qnil;
    rb_hash_foreach(hash, keep_if_i, hash);
    if (n == RHASH_SIZE(hash)) return Qnil;
    return hash;
}