lundi 6 mars 2023

store the value in array and return the function ruby

item has array of hash. ex. item = [{item1},{item2},{item3}]

def function1
   item.map( other_class.call )
end

# other class will return the array which contains string
class other_class
   def call 
     #method which return arrray of strings
   end
end

currently the function1 is returning the array of array which has string values.

function1 output example [["str1"], [], ["str2"], ["str3"], ["str4","str5"]]

I want to modify the function1 which will return the array of string.

expected output = ["str1" "str2", "str3", "str4", "str5"]

Guys, any idea how can I modify the above method.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire