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

OpenStruct#each_pair

ostruct.each_pair {|name, value| block } → ostruct
ostruct.each_pair → Enumerator

Yields all attributes (as symbols) along with the corresponding values or returns an enumerator if no block is given.

Example
require "ostruct"
data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
data.each_pair.to_a   # => [[:country, "Australia"], [:capital, "Canberra"]]
See also #dig #eql? #delete_field #freeze also in 3.4 · 3.3 · 3.2 · 3.1