[HN Gopher] Ruby's hash is a Swiss-army knife ___________________________________________________________________ Ruby's hash is a Swiss-army knife Author : software_writer Score : 19 points Date : 2023-08-20 20:36 UTC (2 hours ago) (HTM) web link (www.akshaykhot.com) (TXT) w3m dump (www.akshaykhot.com) | j_crick wrote: | It should be noted that ** operator works like .merge, and also | accounts for the order of key definition in a given hash | declaration (whatever is declared earlier gets overwritten if a | key with same name is used in the same hash declaration later). | block_dagger wrote: | Ruby's Hash is probably the handiest data structure I've ever | encountered. Thanks Matz. | thibaut_barrere wrote: | Definitely! As a matter of fact, this is the default data | structure I use when writing Ruby ETL code (e.g. | https://github.com/thbar/kiba/wiki). | | Methods like "except" (https://docs.ruby- | lang.org/en/3.2/Hash.html#method-i-except) or "fetch" (raising | an error on missing key) are very convenient to write defensive | data processing code! | | Similarly, in Elixir, I use Maps a lot for the same type of | jobs (https://hexdocs.pm/elixir/1.15.4/Map.html), with similar | properties. ___________________________________________________________________ (page generated 2023-08-20 23:00 UTC)