Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

OpenStruct#dig

ostruct.dig(name, *identifiers) → object

Finds and returns the object in nested objects that is specified by name and identifiers. The nested objects may be instances of various classes. See Dig Methods.

Examples:

Example
require "ostruct"
address = OpenStruct.new("city" => "Anytown NC", "zip" => 12345)
person  = OpenStruct.new("name" => "John Smith", "address" => address)
person.dig(:address, "zip") # => 12345
person.dig(:business_address, "zip") # => nil
See also #delete_field #each_pair #as_json #eql? also in 3.3 · 3.2 · 3.1 · 3.0