Starting with Ruby 3.1, you can omit values in hash literals, meaning you can write:
a = 'some value'
b = 'other value'
h = { a:, b: }
In my opinion, this is one of the coolest syntax features, and I use it all the time when building apps. However, I almost always catch myself asking: should you always name block variables to match the hash key?
# 1.
1.upto(10).each do |value|
hash = { value: }
# other code
end
# 2.
1.upto(10).each do |i|
hash = { value: i }
# other code
end
Have you ever thought about this trade-off? Which style do you prefer?