Have you tried this?
if block_given? && yield(self[x])
This condition will always fail if no blocks are specified, i.e. anything that is in place of # ... will not be evaluated. If you want the condition to be successful if no blocks are specified, do this instead:
if !block_given? || yield(self[x])
Or this, although it seems harder to read to me:
unless block_given? && !yield(self[x])
Jordan running
source share