3 ms·
Ruby’s Hash is probably the handiest data structure I’ve ever encountered. Thanks Matz.
by block_dagger 3y ago
Ruby’s Hash is probably the handiest data structure I’ve ever encountered. Thanks Matz.
- thibaut_barrere 3y agoDefinitely! 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 https://github.com/thbar/kiba/wiki). Methods like "except" (https://docs.ruby-lang.org/en/3.2/Hash.html#method-i-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 https://hexdocs.pm/elixir/1.15.4/Map.html), with similar properties.
- code_biologist 3y agoKiba looks like a really cool framework, thanks for posting it!
- Gigachad 3y agoI wish it was typed though. So many times I’ve seen a function that takes a hash of “options” or “config” and have no idea what that actually contains. Even for official rails methods it’s often complex to know what the possible options are. Some of them seem almost internal with how obscure they are.
- lloeki 3y agoRBS+steep to the rescue! We typed our configuration this way for ddtrace Ruby. On the external (set) side it makes it very easy to explore configuration in an editor, on the internal (get) side it makes us ensure we don't make mistakes.