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.