Filling multidimensional array problem

I

Indra M.

Hi,

I want to extend a complex, multidimensional array with (code snippet):

results.each do |result|
result[1] << [string, array]
puts result[1]
end
puts results

The output of "result[1]" is correct, showing the [string, array] is
attached.
But putting "results" shows, that "array" is not in "results".

Does anyone no why?
 
R

Robert Dober

Hi,

I want to extend a complex, multidimensional array with (code snippet):

results.each do |result|
result[1] << [string, array]
puts result[1]
end
puts results

The output of "result[1]" is correct, showing the [string, array] is
attached.
But putting "results" shows, that "array" is not in "results".
But putting "result" <that is without an s> might be more to your liking.
HTH
Robert
 
I

Indra M.

Robert said:
But putting "result" <that is without an s> might be more to your
liking.

I don't understand what you are meaning.
I have results to be extended.
 
A

Alex Gutteridge

Hi,

I want to extend a complex, multidimensional array with (code
snippet):

results.each do |result|
result[1] << [string, array]
puts result[1]
end
puts results

The output of "result[1]" is correct, showing the [string, array] is
attached.
But putting "results" shows, that "array" is not in "results".

Does anyone no why?


You might have to post working code rather than a snippet. Putting in
some test data seems to work fine in irb:

irb(main):001:0> string = 'hi'
=> "hi"
irb(main):002:0> array = [1,2,3]
=> [1, 2, 3]
irb(main):003:0> results = [[0,[]],[0,[]]]
=> [[0, []], [0, []]]
irb(main):004:0> results.each do |result|
irb(main):005:1* result[1] << [string,array]
irb(main):006:1> puts result[1]
irb(main):007:1> end
hi
1
2
3
hi
1
2
3
=> [[0, [["hi", [1, 2, 3]]]], [0, [["hi", [1, 2, 3]]]]]
irb(main):008:0> puts results
0
hi
1
2
3
0
hi
1
2
3
=> nil

Alex Gutteridge

Department of Biochemistry
University of Cambridge
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top