jeudi 17 août 2017

Return defaul value of hash ruby

I am making a hash like this:

enum_gender={:male=>1,:female=>2, :default_when_fail=>3}

but I need that when I access

enum_gender[:somekey]

It return 3 by default or some value specified

:some_key could be any other :assd, :asf, :asdf

how do I do this ?

Aucun commentaire:

Enregistrer un commentaire