Since you already got the solution to your original question I'll show you how you can refactor this code: Tj Superfly wrote: > #item = url > #species = pet > > def exists(item) > existingitems = YAML.load(File.open("./#{species}.yaml")) > existingitems.each { > |exist| > if exist == item > return false > end > } > return true > end # convention in ruby is to speak in 2nd person, ? is a valid last character in a method definition def exist?(item, species) # depending on your situation you'd better load the yaml files once at the beginning instead of here # YAML.load_file is to favor over YAML.load(File.open) existing_items = YAML.load_file "./#{species}.yaml" # any? is found in Enumerable, it shortcuts and takes a block to test items in the collection against existing_items.any? { |existing| item == existing } end Since most likely your collection even responds to #include? properly, you can use that, so with preloading the files and everything: def initialize @species = {} Species.each { |name| @species[name] = YAML.load_file "./#{name}.yaml" } end def exist?(item, species) @species[name].include?(item) end You might even want to make seperate classes for your species, then you can avoid the 2nd argument entirely. Regards Stefan -- Posted via http://www.ruby-forum.com/.