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#values_at

struct.values_at(selector, ...) → array

Returns the struct member values for each selector as an Array. A selector may be either an Integer offset or a Range of offsets (as in Array#values_at).

Example
Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.values_at(0, 2)   #=> ["Joe Smith", 12345]
See also #values #to_s also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1