samedi 4 avril 2015

Rails return to calling function inside if else block

I am using a recursive function.



def abc
get_course_to_be_deleted( courses, array_course_name, nil )
end

def self.get_course_to_be_deleted( courses, array_course_name, course )
if array_course_name.blank?
#### array_course_name = []
course
else
#### array_course_name = ['Science', 'Maths']
array_course_name.each do |course_name|
course = courses.detect{ |course| course.name == course_name }
course_names = array_course_name - [ course_name ]
get_course_to_be_deleted( course.children, course_names, course )
end
end


end


When array_course_name is blank, course is not getting returned, instead it goes to else block...any solutions???


Aucun commentaire:

Enregistrer un commentaire