I want to find some elegant way to achieve this. Maybe like follwing:
hash={"1"=>"1","2"=>"2"}
r=[]
hash.each do |k,v|
if k!="1"
r<<k
end
end
puts r
Any better way to achieve this?
You can use "array difference":
hash.keys - ['1']
#=> ["2"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With