DEV Community

Raghu Betina
Raghu Betina

Posted on

TIL: Hash value omission in Ruby 3

Today I learned that as of Ruby 3, we can omit values from hashes if the key name matches the expression:

# In Rubies < v3:
a = "alice"
b = "bob"

h = {a: a, b: b}

# In Rubies >= v3:
a = "alice"
b = "bob"

h = {a:, b:}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)