dimanche 10 avril 2016

Search elements of array and return element but keep original class

I have an array my_array that is made up of multiple MyClass objects. I need to search this array and return an object from the array, but keep the objects's class as the original MyClass.

To be clear:

# my_array[0] is a MyClass object
# my_array is an Array

Select works perfectly, but it returns the element as an Array and not as MyClass. For instance:

my_array.select{|element| element[:value] == "good"}

This returns an Array

I need to pass a MyClass object to my view, and this is all happening in the 'MyClassController`

Thoughts?

Aucun commentaire:

Enregistrer un commentaire