-1

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?

alt
  • 13,357
  • 19
  • 80
  • 120
  • What have you tried so far? I think this might be what you are looking for http://stackoverflow.com/questions/3893278/ruby-kind-of-vs-instance-of-vs-is-a – Eric Tobias Mar 06 '13 at 07:37

1 Answers1

2
new_array = [old_array.delete(old_array.detect { |object| object.is_a? Post })]
Amit Kumar Gupta
  • 17,184
  • 7
  • 46
  • 64