Why after this block of code the output is: [9.5]? I mean .. why the delete_if method deletes even my 'a' from my array?
x = [1, 2, 3, 'a', 9.5]
x.delete_if{ |elem| elem.to_i <= 3}
p x
Why after this block of code the output is: [9.5]? I mean .. why the delete_if method deletes even my 'a' from my array?
x = [1, 2, 3, 'a', 9.5]
x.delete_if{ |elem| elem.to_i <= 3}
p x
It's not about delete_if, it's about to_i
'a'.to_i
=> 0
to_i gives you 0 in those cases in which it doesn't know how to make your object an integer