Dynamic Arrary Names

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

···

--
Posted via http://www.ruby-forum.com/.

Hi --

···

On Sun, 13 Jul 2008, M. Muzaffar wrote:

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

--
Rails training from David A. Black and Ruby Power and Light:
   Intro to Ruby on Rails July 21-24 Edison, NJ
   Advancing With Rails August 18-21 Edison, NJ
See http://www.rubypal.com for details and updates!

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

···

On Sun, Jul 13, 2008 at 08:58:22PM +0900, M. Muzaffar wrote:

Thanks Greg

It works for me. So nice of your.

/Muzaffar

Gregory Seidman wrote:

···

On Sun, Jul 13, 2008 at 08:58:22PM +0900, M. Muzaffar wrote:

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

--
Posted via http://www.ruby-forum.com/\.