-
-
Notifications
You must be signed in to change notification settings - Fork 23
Segment: Hash Slices
Somewhat similar to Array Slices and using all rules for Hash Keys, a Hash Slice is a resultant Hash that is composed of only the values from a source Hash for which their keys have names fitting between an alphanumeric start and end value, inclusively. Hash Slice searches are performed against the names of the keys but only the values of matching keys are returned. The locale of the run-time environment controls sorting and matching behavior. The result is always the actual matched values in their original data types, one result per match. So, some results may be scalar values, some may be Arrays, and some may be Hashes; it all depends on what the source value are. Like Array Slice segment notation, a []
pair and the :
symbol are required.
Take for example, this YAML data:
hash_name:
a_key: value_a
b_key: value_b
c_key: value_c
d_key: value_d
e_key: value_e
In order to inclusively select the values of keys from b_key
through d_key
, you could use these YAML Paths: hash_name[b_key:d_key]
or /hash_name[b_key:d_key]
.