For example:
a = [1,2,3,4,5]
a.delete_if { |x| x > 3 }
is equivalent to:
a = [1,2,3,4,5]
a.delete_if.each.each.each.each { |x| x > 3 }
I know a.delete_if
returns an enumerator. But how does it know it should delete object when the each
block returns true? How to implement delete_if
by hand(and in Ruby)?
[1,2,3,4,5].delete_if.each.each.each.each { |x| x > 3 }
Could you please elaborate a bit more on this line? – Egindelete_if.each
the same aseach
? how doesdelete_if
remember what should it do? – Albanian