General

Profile

LevLukomskyi (Lev Lukomskyi)

  • Login: LevLukomskyi
  • Registered on: 12/12/2021
  • Last sign in: 11/21/2025

Issues

open closed Total
Assigned issues 0 0 0
Reported issues 1 0 1

Activity

08/29/2022

12:40 AM Ruby Feature #18959: Handle gracefully nil kwargs eg. **nil
> 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)

08/27/2022

10:13 PM Ruby Feature #18959: Handle gracefully nil kwargs eg. **nil
> 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)

08/26/2022

11:36 PM Ruby Feature #18959: Handle gracefully nil kwargs eg. **nil
> 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)
08:43 PM Ruby Feature #18959: Handle gracefully nil kwargs eg. **nil
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)

08/25/2022

10:32 PM Ruby Feature #18959: Handle gracefully nil kwargs eg. **nil
@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)
01:17 PM Ruby Feature #18959: Handle gracefully nil kwargs eg. **nil
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)
11:36 AM Ruby Feature #18959: Handle gracefully nil kwargs eg. **nil
> 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)

08/24/2022

08:16 PM Ruby Feature #18959: Handle gracefully nil kwargs eg. **nil
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)
11:09 AM Ruby Feature #18959: Handle gracefully nil kwargs eg. **nil
`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)

08/08/2022

07:02 PM Ruby Feature #18959: Handle gracefully nil kwargs eg. **nil
Oh wow, I didn't know that ๐Ÿ˜ฒ `def nil.to_hash = {}` works perfectly well! Many thanks! ๐Ÿ™ LevLukomskyi (Lev Lukomskyi)

Also available in: Atom