Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by Nick Veys for Ruby how to add an element to element to hash that returns hash?

tap will yield the object to a block, and then return it:

my_hash.tap { |h| h['X'] = value }

Be aware that reducing lines of code for the sake of reducing lines of code only reduces readability and clarity of purpose, it rarely improves code quality.


Viewing all articles
Browse latest Browse all 4

Trending Articles