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

Hi –

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

arrary0
arrary1

Try Googling as follows:

create dynamic variables ruby

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

David

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

Thanks Greg

It works for me. So nice of your.

/Muzaffar

Gregory S. 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs