Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Struct#select

struct.select {|obj| block } → array
struct.select → enumerator

Yields each member value from the struct to the block and returns an Array containing the member values from the struct for which the given block returns a true value (equivalent to Enumerable#select).

Example
Lots = Struct.new(:a, :b, :c, :d, :e, :f)
l = Lots.new(11, 22, 33, 44, 55, 66)
l.select {|v| v.even? }   #=> [22, 44, 66]

Struct#filter is an alias for Struct#select.

See also #members #size #length #to_a also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1