I can iterate through an array just fine doing:
def source_names(packages)
files = []
packages.each do |package|
files << (package + ".ads")
files << (package + ".adb")
end
return files
end
But only so long as an array is passed in (or probably any collection). However this fails when only a single package is passed into this method as part of a greater script, because of what looks like the type being a string, instead of a single element in an array:
in 'source_names': undefined method 'each' for "Generics.Mathematics":String (NoMethodError)
So how do I have it not care that only a single element is passed in, where it's only recognized as a string?
Clairification: I know a string doesn't support array methods. My confusion is why i'm getting an array sometimes, and a string othertimes instead of a single element array.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…