Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
OpenStruct#dig
ostruct.dig(name, *identifiers) → object
lib/ostruct.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/ostruct.rb, line 340
def dig(name, *names)
begin
name = name.to_sym
rescue NoMethodError
raise! TypeError, "#{name} is not a symbol nor a string"
end
@table.dig(name, *names)
end
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