The only thing I really miss in the default Ruby hash is property access for keys like JavaScript has.
I know, I know, OStruct does this but it's not the thing that gets built from hash literals so it's less convenient.
It's a minor quibble
I know, I know, OStruct does this but it's not the thing that gets built from hash literals so it's less convenient.
It's a minor quibble
Foo = Struct.new(:a, :b, keyword_init: true) do
def frobz
...
end
end
Structs are quicker to instantiate than classes but slower to call methods on, so if you instantiate a lot but seldom call they're great. Otherwise a class is better.