C
Charles Calvert
I'm using Ruby 1.8.7 patchlevel 249
Is there a more idiomatic way to do the following?
var = hash[key].nil? ? nil : hash[key].downcase
Note that if hash[key] is nil, I want nil assigned to var, so this
won't work:
var = hash[key].downcase unless hash[key].nil?
Obviously I could do this, but I'm trying to keep it on one line:
var = hash[key]
var = var.downcase unless var.nil?
Is there a more idiomatic way to do the following?
var = hash[key].nil? ? nil : hash[key].downcase
Note that if hash[key] is nil, I want nil assigned to var, so this
won't work:
var = hash[key].downcase unless hash[key].nil?
Obviously I could do this, but I'm trying to keep it on one line:
var = hash[key]
var = var.downcase unless var.nil?