rubymotion - Ruby array only storing last item during collect statement -
i have ruby method queries array through search. typed in searchbar appends item array shows on screen. below method:
@churches = ["ugbc", "oak ridge baptist", "calvary"] @search_results = [] def search_for(text) @churches.collect |church| if text == church @search_results << church end end end when code triggered object returned when searched last object in array: "calvary". if search of other items sends empty array. have tried each statement , collect statement , nothing work. how append empty array no matter item search on?
you not using right method. think array#select need. might have substring check text.
here example
text = 'ridge' > churches.select{|c| c.include?(text)} #=> ["oak ridge baptist"]
Comments
Post a Comment