Note that there are some explanatory texts on larger screens.

plurals
  1. PODeep Hash Inspection
    text
    copied!<p>Okay so this is a bit complex but I need to loop through this hash to find if each element meets one of following conditions:</p> <p><strong>The Value is a String</strong></p> <p>or</p> <p><strong>The Value is a Hash, containing Strings, Not Hashes</strong></p> <p>or</p> <p><strong>The Value is a Hash, containing Strings and/or Hashes</strong></p> <p>or</p> <p><strong>The Value is an Array</strong> </p> <p><strong>UPDATE:</strong></p> <p>Something very strange... [EDIT: this is because #collect is returning the hash's key-value pairs, which are arrays]</p> <pre><code>irb&gt; my_hash['gd:name'].collect(&amp;:class) =&gt; [Array, Array] </code></pre> <p>Looking at the hash below should the class of that inner element be a Hash, not an Array?</p> <p>Inspected it looks like:</p> <pre><code>irb&gt; my_hash['gd:name'].collect(&amp;:inspect) =&gt; ["[\"gd:givenName\", {\"$t\"=&gt;\"Thomas\"}]", "[\"gd:familyName\", {\"$t\"=&gt;\"Chapin\"}]"] </code></pre> <p><em>BUT IT BEHAVES LIKE A HASH:</em></p> <pre><code>irb&gt; my_hash['gd:name']['gd:givenName'] =&gt; {"$t"=&gt;"Thomas"} irb&gt; my_hash['gd:name']['gd:givenName']['$t'] =&gt; "Thomas" </code></pre> <hr> <pre><code>{ "gd:etag"=&gt;"\"Rnk7fjVSLyt7I2A9WhVQEU4KRQI.\"", "id"=&gt;{ "$t"=&gt;"da513d38e88d949" }, "gd:name"=&gt;{ "gd:givenName"=&gt;{"$t"=&gt;"Thomas"}, "gd:familyName"=&gt;{"$t"=&gt;"Chapin"} }, "gd:phoneNumber"=&gt;[ { "rel"=&gt;"mobile", "$t"=&gt;"(480) 703-4887" } ], "gd:email"=&gt;[ { "rel"=&gt;"home", "primary"=&gt;"true", "address"=&gt;"tchapin@gmail.com" }, { "rel"=&gt;"work", "address"=&gt;"tom@tornadodesign.com"} ] } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload