> You need to fail when someone passes you garbage (and `nil` is a garbage value in this case), or you need to ensure better default values (e.g., `{}`) at your call sites. When you pass `nil` you make less allocations, also you don't...LevLukomskyi (Lev Lukomskyi)
> I also tend to do `**(options || {})` and I donโt write hard-to-read code like `**({id: id, name: name} if id.present?)`. That's interesting, that you are ok for ```ruby **(options || {}) ``` but not ok for ```ruby **(options ...LevLukomskyi (Lev Lukomskyi)
> because itโs (1) wasteful It wastes what? I don't understand this argument > ... This I can understand because indeed sometimes programmers can put too much in one line. However there are only two operators in that line โ `if` an...LevLukomskyi (Lev Lukomskyi)
Currently: ```ruby "xyz".sub(/y/, nil) #=> TypeError: no implicit conversion of nil into String def nil.to_hash; {} end "xyz".sub(/y/, nil) #=> "xz" ``` Ok, the behavior is different, but it doesn't mean that we cannot implement the fea...LevLukomskyi (Lev Lukomskyi)
@austin, your example is a perfect example of "overengineering". We could argue about "clearness", although about "conciseness" it's easy to check โ option 1: 72 characters, option 2: 62 characters, so option 2 is 15% more concise, cl...LevLukomskyi (Lev Lukomskyi)
I'm not that much concerned about the performance but about readability. Your solution with `compact` is probably good for that particular case but it cannot solve all other cases with an arbitrary hash plugged into the main hash on an a...LevLukomskyi (Lev Lukomskyi)
> I meant to simply use compact! in a different statement, not in a chain. If use `compact!` as a different statement then you need to make a variable, you have to make a mental effort to make up the name for that variable and repeat ...LevLukomskyi (Lev Lukomskyi)
2. => more specifically `.tap(&:compact!)` since `compact!` may return `nil` if nothing changed. 3. there might be also a case when you want to merge another hash under some conditions, eg.: ```ruby { some: 'value', **({ id: id, na...LevLukomskyi (Lev Lukomskyi)
`compact` way looks good indeed, although: 1. it removes all `nil`s from the hash, which might be undesired in some cases 2. it creates hash duplicate each time, while kwargs way creates temporary hash only if a condition is met, though ...LevLukomskyi (Lev Lukomskyi)