woops i send in my broken version.
line 7 of my class
@actie.split!(",")
should be removed....
Op 21-2-2012 7:14, Catsquotl schreef:
> Hi,
>
> I have a class which an each method to itterate over its instance
> variables.
> I am trying to do a string search on all those variables.
>
> However it seems to just evaluate the last yielded instance var.
> the following test.
> -----
> a = Acupunt.new(["bl","vloed","tingping","pols","luo","klaart
> hitte","verdrijft wind"])
> a.each {|check| puts check}
> -----
> prints out all vars.
>
> a.search("bl") however
> prints "not found ["klaart hitte", "verdrijft wind"] is not bl"
>
> a.search("hitte")
> prints found
>
> I don't understand why search my search only works if the last yielded
> var matches en not the previous ones
> Anyone want to point me in the right direction?
>
> Eelco
> -------------------------------------------
> class Acupunt
> include Enumerable
>
> attr_reader :afk, :name,:chname, :locatie, :aard, :actie
>
> def initialize(arr)
> set_instance_variables arr
> @actie.split!(",")
> end
>
> def set_instance_variables arr
> @afk=arr[0]
> @name=arr[1]
> @chname=arr[2]
> @locatie=arr[3]
> @aard=arr[4]
> @actie=arr[5..-1]
> end
>
> def each
> yield "#{@afk}"
> yield "#{@name}"
> yield "#{@chname}"
> yield "#{@locatie}"
> yield "#{@aard}"
> yield "#{@actie}"
> end
>
> def search str
> self.each do |check|
> if check.eql? str
> "found"
> else
> "not found #{check} is not #{str}"
> end
> end
> end
> end
>
>