The following line is working fine in ruby 1.8.7 and not in 1.8.6. What alternative I can use in 1.8.6
x = [3,4,5,6,7,78,4,3,2,5,5,3]
x.count(3)
=> 3
Since count is not a method in Array in version 1.8.6, I am getting this error. Is there a similar method in this version?
x = [3,4,5,6,7,78,4,3,2,5,5,3]
x.grep(3).size
#=> 3
count = x.select {|e| e == 3}.size
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