Delete object from array of object

Suppose a class:

class C_L_A_S_S
attr_accessor :a, :b, :c
end

I have an array of object of class above.
say a_of_obj

Now I want to delete the element from a_of_obj whose a=33
Could you please tell me the best way to do it?

···

--
Posted via http://www.ruby-forum.com/.

Is this homework?

Sam

···

On 10/02/2012 11:06 AM, ajay paswan wrote:

Suppose a class:

class C_L_A_S_S
attr_accessor :a, :b, :c
end

I have an array of object of class above.
say a_of_obj

Now I want to delete the element from a_of_obj whose a=33
Could you please tell me the best way to do it?

because it's extremely useful :slight_smile:

···

2012/10/2 ajay paswan <lists@ruby-forum.com>

Suppose a class:

class C_L_A_S_S
attr_accessor :a, :b, :c
end

I have an array of object of class above.
say a_of_obj

Now I want to delete the element from a_of_obj whose a=33
Could you please tell me the best way to do it?

--
Posted via http://www.ruby-forum.com/\.

Look for Array in http://ruby-doc.org/core-1.9.3/\. Bookmark this page

a_of_obj.delete_if {|obj| obj.a == 33}

···

--
Posted via http://www.ruby-forum.com/.

Sam Duncan wrote in post #1078258:

Could you please tell me the best way to do it?

Is this homework?

No I am just playing around wit ruby, and sorry there is a delete
function for exactly the same purpose.

···

On 10/02/2012 11:06 AM, ajay paswan wrote:
Sam

--
Posted via http://www.ruby-forum.com/\.