So I have an array of active record objects.
I need to grab the first existing object in that array with a class of post
, move it to a brand new array so that it no longer exists in the initial one.
What's the most optimal way to do this in Ruby?
So I have an array of active record objects.
I need to grab the first existing object in that array with a class of post
, move it to a brand new array so that it no longer exists in the initial one.
What's the most optimal way to do this in Ruby?
new_array = [old_array.delete(old_array.detect { |object| object.is_a? Post })]