I'm trying to find an elegant and compact way to convert hash keys into array that contains only those that have true as value
example = {"foo" => true, "bar" => false, "baz" => true}
become
example = ["foo", "baz"]
example = example.keys.select {|key| example[key].eql? true}
p example
output
["foo", "baz"]
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