HEX
Server: Apache
System: Linux vps-cdc32557.vps.ovh.ca 5.15.0-156-generic #166-Ubuntu SMP Sat Aug 9 00:02:46 UTC 2025 x86_64
User: hanode (1017)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //usr/share/ri/3.0.0/system/page-dig_methods_rdoc.ri
U:RDoc::TopLevel[	iI"dig_methods.rdoc:EFcRDoc::Parser::Simpleo:RDoc::Markup::Document:@parts[(S:RDoc::Markup::Heading:
leveli:	textI"Dig Methods;To:RDoc::Markup::BlankLineo:RDoc::Markup::Paragraph;[I"JRuby's +dig+ methods are useful for accessing nested data structures.;T@
o;
;[I"Consider this data:;To:RDoc::Markup::Verbatim;[I"item = {
;TI"  id: "0001",
;TI"  type: "donut",
;TI"  name: "Cake",
;TI"  ppu: 0.55,
;TI"  batters: {
;TI"    batter: [
;TI"*      {id: "1001", type: "Regular"},
;TI",      {id: "1002", type: "Chocolate"},
;TI",      {id: "1003", type: "Blueberry"},
;TI".      {id: "1004", type: "Devil's Food"}
;TI"    ]
;TI"
  },
;TI"  topping: [
;TI"%    {id: "5001", type: "None"},
;TI"'    {id: "5002", type: "Glazed"},
;TI"&    {id: "5005", type: "Sugar"},
;TI"/    {id: "5007", type: "Powdered Sugar"},
;TI"9    {id: "5006", type: "Chocolate with Sprinkles"},
;TI"*    {id: "5003", type: "Chocolate"},
;TI"%    {id: "5004", type: "Maple"}
;TI"	  ]
;TI"}
;T:@format0o;
;[I"+Without a +dig+ method, you can write:;To;;[I"8item[:batters][:batter][1][:type] # => "Chocolate"
;T;0o;
;[I"(With a +dig+ method, you can write:;To;;[I"<item.dig(:batters, :batter, 1, :type) # => "Chocolate"
;T;0o;
;[I"8Without a +dig+ method, you can write, erroneously ;TI"N(raises <tt>NoMethodError (undefined method `[]' for nil:NilClass)</tt>):;To;;[I"'item[:batters][:BATTER][1][:type]
;T;0o;
;[I"XWith a +dig+ method, you can write (still erroneously, but avoiding the exception):;To;;[I"4item.dig(:batters, :BATTER, 1, :type) # => nil
;T;0S;	;
i;I"Why Is +dig+ Better?;T@
o:RDoc::Markup::List:
@type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o;
;[I"6It has fewer syntactical elements (to get wrong).;To;;0;[o;
;[I"It reads better.;To;;0;[o;
;[I"<It does not raise an exception if an item is not found.;T@
S;	;
i;I"How Does +dig+ Work?;T@
o;
;[I"The call sequence is:;To;;[I"obj.dig(*identifiers)
;T;0o;
;[I"GThe +identifiers+ define a "path" into the nested data structures:;To;;;;[	o;;0;[o;
;[I"LFor each identifier in +identifiers+, calls method \#dig on a receiver ;TI"with that identifier.;To;;0;[o;
;[I""The first receiver is +self+.;To;;0;[o;
;[I"REach successive receiver is the value returned by the previous call to +dig+.;To;;0;[o;
;[I"PThe value finally returned is the value returned by the last call to +dig+.;T@
o;
;[I"RA +dig+ method raises an exception if any receiver does not respond to \#dig:;To;;[I"h = { foo: 1 }
;TI"=# Raises TypeError (Integer does not have #dig method):
;TI"h.dig(:foo, :bar)
;T;0S;	;
i;I"What Else?;T@
o;
;[I"?The structure above has \Hash objects and \Array objects, ;TI".both of which have instance method +dig+.;T@
o;
;[I"LAltogether there are six built-in Ruby classes that have method +dig+, ;TI"Athree in the core classes and three in the standard library.;T@
o;
;[I"In the core:;To;;;;[o;;0;[o;
;[I"8Array#dig: the first argument is an \Integer index.;To;;0;[o;
;[I"+Hash#dig: the first argument is a key.;To;;0;[o;
;[I"-Struct#dig: the first argument is a key.;T@
o;
;[I"In the standard library:;To;;;;[o;;0;[o;
;[I":OpenStruct#dig: the first argument is a \String name.;To;;0;[o;
;[I"QCSV::Table#dig: the first argument is an \Integer index or a \String header.;To;;0;[o;
;[I"OCSV::Row#dig: the first argument is an \Integer index or a \String header.;T:
@file@:0@omit_headings_from_table_of_contents_below0