Can this be usefull?

Discussion in 'Ruby' started by Ralf Müller, Oct 12, 2005.

  1. Ralf Müller

    Ralf Müller Guest

    Hi,

    i had an idea of a cyclic list. It came to my mind months ago and the
    implementation in ruby was so simple:

    class RoundList < Array
    def initialize(size)
    @@size = size
    end
    def add(k,v)
    self[k%@@size] = v
    end
    def get(i)
    self[i%@@size]
    end
    end
    # r = RoundList.new(3)
    # => []
    # r.add(1,"eins")
    # => "eins"
    # r
    # => [nil, "eins"]
    # r.add(0,r)
    # => [[...], "eins"]
    # r.add(2,r)
    # => [[...], "eins", [...]]
    # r.get(0)
    # => [[...], "eins", [...]]
    # r.get(0).get(0)
    # => [[...], "eins", [...]]
    # r.get(0).get(0).get(2)
    # => [[...], "eins", [...]]

    when I saw this, i had a weird feeling of complexity. Mixing different
    RoundLists, fasten them with knots, creating some kind loop-structure and all
    this seems to be endless because r.get(0).get(0) == r.get(0).get(0).get(0) ...
    I couldn't and cannot imagine, how this construction can be usefull.

    If anyone of you CAN imagine, please let me know.

    best regards
    ralf


    --
    > "not using Ruby is punishment enough"
    > -- James Britt, 8.5.2005,
    Ralf Müller, Oct 12, 2005
    #1
    1. Advertising

  2. Ralf Müller

    Trans Guest

    Hey, intersteing --a Modal Array! :) I'm not sure of use case, but its
    certainly neato. One fix though, use @size rather then @@size.

    class RoundList < Array
    def initialize(size)
    @size = size
    end
    def add(k,v)
    self[k%@size] = v
    end
    def get(i)
    self[i%@size]
    end
    end

    T.
    Trans, Oct 13, 2005
    #2
    1. Advertising

  3. Ralf Müller

    Ralf Müller Guest

    Re: [bulk]: Re: Can this be usefull?

    On Thu, 13 Oct 2005 11:41:53 +0900
    "Trans" <> wrote:

    > Hey, intersteing --a Modal Array! :) I'm not sure of use case, but its
    > certainly neato. One fix though, use @size rather then @@size.
    >
    > class RoundList < Array
    > def initialize(size)
    > @size = size
    > end
    > def add(k,v)
    > self[k%@size] = v
    > end
    > def get(i)
    > self[i%@size]
    > end
    > end
    >
    > T.


    Hi T.,
    thanks for the fix.
    Perhaps the visualization of such objects looks interesting.

    Ralf
    Ralf Müller, Oct 13, 2005
    #3
    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. softmyth
    Replies:
    6
    Views:
    2,488
    Robert Klemme
    May 29, 2006
  2. Osiris
    Replies:
    8
    Views:
    332
  3. Rodrick Brown

    lexx/yacc usefull ? when why ?

    Rodrick Brown, May 12, 2005, in forum: C Programming
    Replies:
    4
    Views:
    491
    BGreene
    May 15, 2005
  4. Replies:
    0
    Views:
    341
  5. George Hester
    Replies:
    28
    Views:
    222
    George Hester
    Aug 15, 2003
Loading...

Share This Page