Can anyone show me a ruby way of checking if a key exists in a hash and if it does not then give it a default value. I'm assuming there is a one liner using unless to do this but I'm not sure what to use.
If you are storing a default value that might be nil and you need to calculate it at storage time:
hash = {} ... hash.fetch(key) {|k| hash[k] = calc_default()}