Can this be usefull?

R

Ralf Müller

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


--
 
T

Trans

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.
 
R

Ralf Müller

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
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top