Dynamic Arrary Names

M

M. Muzaffar

Is there any way in ruby to create dynamic array names?

correctarrayfiles=Dir.glob("array_ast_correct_*.rb").size
correctarrayfiles.times do |num|
correctfiles=findbug.file_exist("array_ast_correct")
array+num=findbug.mark_arrary(correctfiles[num])
end

There would be then a new arrays like

arrary0
arrary1
....
....

/Muzaffar
 
D

David A. Black

Hi --

Is there any way in ruby to create dynamic array names?

correctarrayfiles=Dir.glob("array_ast_correct_*.rb").size
correctarrayfiles.times do |num|
correctfiles=findbug.file_exist("array_ast_correct")
array+num=findbug.mark_arrary(correctfiles[num])
end

There would be then a new arrays like

arrary0
arrary1

Try Googling as follows:

create dynamic variables ruby

As you'll see, it's impossible (or nearly so) and ill-advised.


David
 
G

Gregory Seidman

Is there any way in ruby to create dynamic array names?

correctarrayfiles=Dir.glob("array_ast_correct_*.rb").size
correctarrayfiles.times do |num|
correctfiles=findbug.file_exist("array_ast_correct")
array+num=findbug.mark_arrary(correctfiles[num])
end

There would be then a new arrays like

arrary0
arrary1
....
....

You are overcomplicating.

correctarrayfiles = Dir.glob("array_ast_correct_*.rb").size
corrected_files = (0...correctarrayfiles).map do |num|
correctfiles = findbug.file_exist("array_ast_correct")
findbug.mark_arrary(correctfiles[num])
end

Now corrected_files contains an array of whatever findbug.mark_arrary
returns. This is semantically identical to your original code, though I
think there are probably issues with the original code, including typos.
/Muzaffar
--Greg
 
M

M. Muzaffar

Thanks Greg

It works for me. So nice of your.

/Muzaffar

Gregory said:
arrary0
arrary1
....
....

You are overcomplicating.

correctarrayfiles = Dir.glob("array_ast_correct_*.rb").size
corrected_files = (0...correctarrayfiles).map do |num|
correctfiles = findbug.file_exist("array_ast_correct")
findbug.mark_arrary(correctfiles[num])
end

Now corrected_files contains an array of whatever findbug.mark_arrary
returns. This is semantically identical to your original code, though I
think there are probably issues with the original code, including typos.
/Muzaffar
--Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

While loop query 2
Trying to creade method .between() 3
Java 1
Yahoo email "search and destroy" 0
Pygame animation help!!!! 1
Range / empty list issues?? 1
Copy string from 2D array to a 1D array in C 1
Tasks 1

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,663
Latest member
josh5959

Latest Threads

Top