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?
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?
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
Sam D. 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
a_of_obj.delete_if {|obj| obj.a == 33}
2012/10/2 ajay paswan [email protected]
Could you please tell me the best way to do it?
–
Posted via http://www.ruby-forum.com/.Look for Array in Index of Files, Classes & Methods in Ruby 1.9.3 (Ruby 1.9.3). Bookmark this page
because it’s extremely useful
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs