I am iterating through this_dir,
this_dir = Dir.new(".") putsing each .rb file. With the folders (everything that aren't .rb), I would like to open them, list their contents, and set them to a variable. I created an array names to get the variable name from, and planned to iterate through it by calling it with names_index and adding 1 to that.
names = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'n', 'm', 'o', 'p'] names_index = 0 Unfortunately, the closest thing I know how to do with Array values is puts them, which makes it a string.
this_dir.each do |file| if file.include?("*.rb") puts file else .... end end How do I turn the array values into variable names?
file.include?("*.rb")will only be true for the literal string '*.rb'. You need to put the wildcard inDir#glob, as @Jordan has done. You have made no reference tonamesorname_indexafter defining those variables.names.namesandname_indexin the spot where I substituted..... Unfortunately it wouldn't have had the desired behavior, so I left the dots. I wrote those two variables in my question so that my explanation would be as thorough as possible.file.include?("*.rb")will only be true for filenames that contain the literal string'*.rb'; that is,'*'does not act as a wildcard here.