mardi 21 février 2017

Ruby error - Undefined Method

I am try to write a function that will find the items in an array which match the string passed to the function. See code below.

class Island 
  def filter(string) 
    for element in self
      if element.include? (string)
        yield(element)
      end
    end
  end 
end
list =    ["sasha","rory","rob","anthony","andre","tariq","kimberly","antoinette"]
list.filter("an"){|i| puts i}</i>

How i keep getting "undefined method 'filer' for #

I'm not sure what i'm doing wrong.




Aucun commentaire:

Enregistrer un commentaire