3 ms·
There is nothing “dangerous” about this if you know the behavior. In Ruby nil is a representation of emptiness, so when using the to_ conversion methods you wi
by transfire 3y ago
There is nothing “dangerous” about this if you know the behavior.
In Ruby nil is a representation of emptiness, so when using the to_ conversion methods you will get an empty instance of a type. If you don’t want this behavior you use a constructor instead.
FYI For a long time there was no nil.to_h and there was some consternation about adding it. But finally it was embraced and this emptiness notion solidified into the language for good.
- eyelidlessness 3y ago> There is nothing “dangerous” about this if you know the behavior. There’s nothing dangerous about any functionality in any language if you know the behavior. Not that I’m saying this is a particularly dangerous functionality of Ruby (coming mostly from other dynamic/scripting languages, it seems refreshingly explicit if nothing else), but I don’t think expertise in usage of a footgun is what should determine whether it’s a footgun.