I want to count how much D and E and F contains the array ary in total.
I can do it like
ary.count('D') + ary.count('E') + ary.count('F')
or like
count = 0
'DEF'.split('').each do |letter|
count += ary.count(letter)
end
count
but both of it don't look very smart to me, is there a better way in ruby? Unfortunately, .count('D','E','F') does not work.
aryan array of 1-character strings? If not, and one element ofaryis"DDr", does that count as0,1or2'D''s?