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

[ad_1]

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

[ad_2]

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