4 ms·
> Sawyer is a crazy class that converts a hash to an object whose methods are based on the hash's key: For those not familiar with Ruby terminology, "hash" in
by paulgb 4y ago
> Sawyer is a crazy class that converts a hash to an object whose methods are based on the hash's key:
For those not familiar with Ruby terminology, "hash" in this context means what other languages would call a hash map, associative array, or dictionary. At first I thought it was referring to the hash of a value, and couldn't grok it.
- btown 4y agoFor those on the Python side of things, https://box.readthedocs.io/en/development/ https://box.readthedocs.io/en/development/ does something similar and is a great utility to reach for when you're handling trusted JSON-like data and need an API-like interface. (The Django templating language does this too, albeit in a more magical way: https://docs.djangoproject.com/en/4.1/ref/templates/language/#variables https://docs.djangoproject.com/en/4.1/ref/templates/language...) Just... make sure you're aware of the issue that the OP's RCE brings up!
- 3PS 4y ago> "hash" in this context means what other languages would call a hash map Interesting. The only other time I've seen this term used for a hash map is in the context of Redis hashes [0], which confused me to no end when I first encountered them for the same reason. Given that Redis itself is written in C, I wonder where the term originated. [0] https://redis.io/docs/data-types/hashes/ https://redis.io/docs/data-types/hashes/
- syrrim 4y agoPerl, probably.
- danielheath 4y agoThis got me curious, so I went and looked what it was called in a few languages. Perl: Hash Ruby: Hash PHP: HashMap Java: HashMap Haxe: Map Golang: map Swift: Dict Python: Dict C#: Dictionary Javascript: Object Redis: Hash Postgresql: hstore, json
- pclmulqdq 4y agoC++: unordered_map
- duncan-donuts 4y agoDoes PHP have a HashMap class now? I haven’t written PHP for a few years now but associative array used to be how they were referred to.
- meling 4y agoYeah, I pretty sure Perl also called them associative arrays, but like you I haven’t written much Perl since Perl 4/5.
- darrenf 4y agoIn all my time as a Perl dev (since 1996) I don't think I've ever heard the term "associative array" except at the start of `perldoc perldata` - which says they're known as hashes and then never uses the term again. DESCRIPTION Variable names Perl has three built-in data types: scalars, arrays of scalars, and associative arrays of scalars, known as "hashes". A scalar is a single string (of any size, limited only by the available memory), number, or a reference to something (which will be discussed in perlref). Normal arrays are ordered lists of scalars indexed by number, starting with 0. Hashes are unordered collections of scalar values indexed by their associated string key. Hash is ubiquitous.
- draegtun 4y agoYes they used to be called Associative Arrays. I think the change occurred between Perl4 & Perl5. In Programming Perl it says "Associative Arrays" in 1st edition and "Hashes (Associative Arrays)" in 2nd edition. NB. 2nd edition was the first to cover Perl5
- kijin 4y agoIt doesn't, at least according to the current documentation. Not sure why they would need a class for that when they already have a primitive type that does the job. I guess maybe a new OO interface will have its parameters ordered more consistently?
- synu 4y agoThe oldest example I can think of is Perl.