[Solved] Concatinate preceding “and” for any key which is second or more [closed]


You can use select method and join method to add “and” to each key.

hash = {key1: true, key2: false, key3: true, key4: true}
hash.select{|k, v| v}.keys.join(" and ")
# => "key1 and key3 and key4"

2

solved Concatinate preceding “and” for any key which is second or more [closed]