Whenever it is possible, I put code readability in front of performance (sometimes any performance gain can be crucial).


Today the method Hash#delete_if came in handy:

``` ruby
hash.delete_if { |k, v| v.nil? }
```


That line will delete all elements which value is ```nil```. You can also achieve a recursive solution with the following code:

``` ruby
hash.delete_if{|k, v| v.nil? or v.instance_of?(Hash) && v.delete_blank.nil?}
```


But how did it helped me today?
That was my efficient code:

``` ruby
if father
if mother
{ dad: father.name, mom: mother.name}
else
{ dad: father.name, mom: mother.name}
end
else
{}
end
```


And now the same behaviour, less efficient, but at my eyes much more readable, expressive, and easy to reuse:

``` ruby
{ dad: father && father.name, mom: mother && mother.name}.delete_if { |k, v| v.empty? }
```