Filling multidimensional array problem

Discussion in 'Ruby' started by Indra M., Jul 22, 2008.

  1. Indra M.

    Indra M. Guest

    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?
    --
    Posted via http://www.ruby-forum.com/.
     
    Indra M., Jul 22, 2008
    #1
    1. Advertising

  2. Indra M.

    Robert Dober Guest

    On Tue, Jul 22, 2008 at 12:45 PM, Indra M. <> wrote:
    > 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
    --
    http://ruby-smalltalk.blogspot.com/

    There's no one thing that's true. It's all true.
    --
    Ernest Hemingway
     
    Robert Dober, Jul 22, 2008
    #2
    1. Advertising

  3. Indra M.

    Indra M. Guest

    Robert Dober wrote:

    > 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.
    --
    Posted via http://www.ruby-forum.com/.
     
    Indra M., Jul 22, 2008
    #3
  4. On 22 Jul 2008, at 11:45, Indra M. wrote:

    > 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?
    > --
    > Posted via http://www.ruby-forum.com/.
    >



    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
     
    Alex Gutteridge, Jul 22, 2008
    #4
  5. Indra M.

    Robert Dober Guest

    On Tue, Jul 22, 2008 at 1:18 PM, Indra M. <> wrote:
    > Robert Dober wrote:
    >
    >> 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.

    no
    --
    http://ruby-smalltalk.blogspot.com/

    There's no one thing that's true. It's all true.
    --
    Ernest Hemingway
     
    Robert Dober, Jul 22, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. c19h28o2

    Multidimensional array pointer problem

    c19h28o2, Sep 26, 2006, in forum: C Programming
    Replies:
    6
    Views:
    492
    Barry Schwarz
    Sep 28, 2006
  2. Replies:
    12
    Views:
    588
    Vladimir
    Nov 22, 2005
  3. MarsTeam

    int array filling

    MarsTeam, Oct 15, 2007, in forum: C Programming
    Replies:
    0
    Views:
    355
    MarsTeam
    Oct 15, 2007
  4. Mohsen Pahlevanzadeh
    Replies:
    0
    Views:
    147
    Mohsen Pahlevanzadeh
    Sep 9, 2013
  5. MRAB
    Replies:
    0
    Views:
    134
Loading...

Share This Page