Array disorder in ruby 1.8.6

Discussion in 'Ruby' started by Frantisek Havluj, Apr 4, 2008.

  1. Hello,

    I suppose I found a bug in ruby (or behavior that I am unable to
    explain). My version is, exactly, ruby 1.8.6 (2007-03-13 patchlevel 0)
    [universal-darwin8.0]

    problem is in this method:

    def plotresults(results,runset)
    ...
    runset.each{|k| f.printf("%-*s",ns,k)}
    ...
    end

    each iterator just prints the items of the runset array out of order.
    however, if I just evaluate the array anywhere in the method, everything
    is ok:

    def plotresults(results,runset)
    runset
    ...
    runset.each{|k| f.printf("%-*s",ns,k)}
    ...
    end

    Not much more to say about that. Can anybody explain to me why Ruby
    should behave like that?
    --
    Posted via http://www.ruby-forum.com/.
     
    Frantisek Havluj, Apr 4, 2008
    #1
    1. Advertising

  2. Frantisek Havluj

    Jano Svitok Guest

    On Fri, Apr 4, 2008 at 1:57 PM, Frantisek Havluj <> wrote:
    > Hello,
    >
    > I suppose I found a bug in ruby (or behavior that I am unable to
    > explain). My version is, exactly, ruby 1.8.6 (2007-03-13 patchlevel 0)
    > [universal-darwin8.0]
    >
    > problem is in this method:
    >
    > def plotresults(results,runset)
    > ...
    > runset.each{|k| f.printf("%-*s",ns,k)}
    > ...
    > end
    >
    > .each iterator just prints the items of the runset array out of order.
    > however, if I just evaluate the array anywhere in the method, everything
    > is ok:
    >
    > def plotresults(results,runset)
    > runset
    > ...
    > runset.each{|k| f.printf("%-*s",ns,k)}
    > ...
    > end
    >
    > Not much more to say about that. Can anybody explain to me why Ruby
    > should behave like that?


    One question: is runset really an Array or a Set? Set doesn't keep the order.

    Jano
     
    Jano Svitok, Apr 4, 2008
    #2
    1. Advertising

  3. Hi --

    On Fri, 4 Apr 2008, Frantisek Havluj wrote:

    > Hello,
    >
    > I suppose I found a bug in ruby (or behavior that I am unable to
    > explain). My version is, exactly, ruby 1.8.6 (2007-03-13 patchlevel 0)
    > [universal-darwin8.0]
    >
    > problem is in this method:
    >
    > def plotresults(results,runset)
    > ...
    > runset.each{|k| f.printf("%-*s",ns,k)}
    > ...
    > end
    >
    > .each iterator just prints the items of the runset array out of order.
    > however, if I just evaluate the array anywhere in the method, everything
    > is ok:
    >
    > def plotresults(results,runset)
    > runset
    > ...
    > runset.each{|k| f.printf("%-*s",ns,k)}
    > ...
    > end
    >
    > Not much more to say about that. Can anybody explain to me why Ruby
    > should behave like that?


    It's impossible to comment without seeing the code where runset is
    created.


    David

    --
    Rails training from David A. Black and Ruby Power and Light:
    ADVANCING WITH RAILS April 14-17 New York City
    INTRO TO RAILS June 9-12 Berlin
    ADVANCING WITH RAILS June 16-19 Berlin
    See http://www.rubypal.com for details and updates!
     
    David A. Black, Apr 4, 2008
    #3
  4. 2008/4/4, Frantisek Havluj <>:

    > I suppose I found a bug in ruby (or behavior that I am unable to
    > explain). My version is, exactly, ruby 1.8.6 (2007-03-13 patchlevel 0)
    > [universal-darwin8.0]
    >
    > problem is in this method:
    >
    > def plotresults(results,runset)
    > ...
    > runset.each{|k| f.printf("%-*s",ns,k)}
    > ...
    > end
    >
    > .each iterator just prints the items of the runset array out of order.


    What exactly do you mean by "out of order"? What order? What type is runset?

    > however, if I just evaluate the array anywhere in the method, everything
    > is ok:


    What do you mean be "evaluate"?

    > def plotresults(results,runset)
    > runset
    > ...
    > runset.each{|k| f.printf("%-*s",ns,k)}
    > ...
    > end
    >
    > Not much more to say about that. Can anybody explain to me why Ruby
    > should behave like that?


    You need to say more about that - otherwise we can't say much more about it.

    Cheers

    robert

    --
    use.inject do |as, often| as.you_can - without end
     
    Robert Klemme, Apr 4, 2008
    #4
    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. David

    the Alphabetical Disorder

    David, Feb 27, 2004, in forum: Java
    Replies:
    4
    Views:
    489
    Collin VanDyck
    Feb 27, 2004
  2. Mara Guida

    const and array of array (of array ...)

    Mara Guida, Sep 2, 2009, in forum: C Programming
    Replies:
    3
    Views:
    496
    David RF
    Sep 3, 2009
  3. anne001
    Replies:
    1
    Views:
    470
  4. Tom
    Replies:
    3
    Views:
    213
    salsablr
    Dec 20, 2004
  5. Tuan  Bui
    Replies:
    14
    Views:
    476
    it_says_BALLS_on_your forehead
    Jul 29, 2005
Loading...

Share This Page