Quantcast
Viewing latest article 3
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 latest article 3
Browse Latest Browse All 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>