本文簡要介紹ruby語言中 OpenStruct.dig
的用法。
用法
dig(name, *identifiers) → object
在 name
和 identifiers
指定的嵌套對象中查找並返回對象。嵌套對象可以是各種類的實例。見Dig Methods。
例子:
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
相關用法
- Ruby OpenStruct.delete_field用法及代碼示例
- Ruby OpenStruct.ostruct[name] =用法及代碼示例
- Ruby OpenStruct.==用法及代碼示例
- Ruby OpenStruct.each_pair用法及代碼示例
- Ruby OpenStruct.new用法及代碼示例
- Ruby OpenStruct.ostruct[name]用法及代碼示例
- Ruby OpenStruct類用法及代碼示例
- Ruby OpenSSL.fips_mode =用法及代碼示例
- Ruby OpenSSL模塊用法及代碼示例
- Ruby OpenSSL.print_mem_leaks用法及代碼示例
- Ruby OpenSSL.Digest用法及代碼示例
- Ruby Open3.capture3用法及代碼示例
- Ruby Open3.capture2用法及代碼示例
- Ruby Open3.capture2e用法及代碼示例
- Ruby Open3.popen2e用法及代碼示例
- Ruby OpenRead.open用法及代碼示例
- Ruby Open3.popen3用法及代碼示例
- Ruby Open3.popen2用法及代碼示例
- Ruby Open3.pipeline用法及代碼示例
- Ruby OpenURI模塊用法及代碼示例
- Ruby Open3.pipeline_rw用法及代碼示例
- Ruby Open3.pipeline_w用法及代碼示例
- Ruby Open3.pipeline_r用法及代碼示例
- Ruby Open3.pipeline_start用法及代碼示例
- Ruby Option.level用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 OpenStruct.dig。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。