Forum: Ruby delete object from array of object

Posted by Prog Rammer (proggrammer)
on 2012-10-02 00:06
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 by Sam Duncan (Guest)
on 2012-10-02 00:13
(Received via mailing list)
On 10/02/2012 11:06 AM, ajay paswan wrote:
> Could you please tell me the best way to do it?
>

Is this homework?

Sam
Posted by Prog Rammer (proggrammer)
on 2012-10-02 00:39
Sam Duncan wrote in post #1078258:
> On 10/02/2012 11:06 AM, ajay paswan wrote:
>> 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.
> Sam
Posted by Joel Pearson (virtuoso)
on 2012-10-02 00:41
a_of_obj.delete_if {|obj| obj.a == 33}
Posted by "Иван Бишевац" <ivan.bisevac@gmail.com> (Guest)
on 2012-10-02 00:41
(Received via mailing list)
2012/10/2 ajay paswan <lists@ruby-forum.com>

> 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
because it's extremely useful :)
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.