ruby add key to hash without value -
is possible add together key hash without value? i've created hash(@j) , have method:
def add(hash) @j.merge!(hash) end
how create possible add together keys, without value, example
@j.add('fish') puts @j.entries puts @j.keywords => {'fish' => nil} => fish
my current code allows me add together key , value this:
@j.add('fish' => 'animal')
but not if above.... key
you can add together hash nil value:
@j.add {:key => nil}
or edit add together method:
def add(key_or_hash) hash = key_or_hash.is_a?(hash) ? key_or_hash : {key_or_hash.to_sym => nil} @j.merge! hash end
ruby
No comments:
Post a Comment