Peña, Botp
8/17/2007 8:50:00 AM
From: Josselin [mailto:josselin@wanadoo.fr]
# I have an array anArray = [ object_1, object_2, ...... object_n]
# I would like to delete an object in it, if
# object.attribute_x = anInteger
delete_if changes the array
irb(main):055:0> a=["a",1,"b",2,3,"c",4]
=> ["a", 1, "b", 2, 3, "c", 4]
irb(main):056:0> a.delete_if{|x| x.is_a? Integer}
=> ["a", "b", "c"]
irb(main):057:0> a
=> ["a", "b", "c"]
reject creates another array copy
irb(main):061:0> a.reject{|x| x.is_a? Integer}
=> ["a", "b", "c"]
select is like reject but w reverse logic
irb(main):066:0> a.select{|x| not x.is_a? Integer}
=> ["a", "b", "c"]
kind regards -botp