Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Can this be usefull?

Reply
Thread Tools

Can this be usefull?

 
 
Ralf Müller
Guest
Posts: n/a
 
      10-12-2005
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, http://www.velocityreviews.com/forums/(E-Mail Removed)



 
Reply With Quote
 
 
 
 
Trans
Guest
Posts: n/a
 
      10-13-2005
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.

 
Reply With Quote
 
 
 
 
Ralf Müller
Guest
Posts: n/a
 
      10-13-2005
On Thu, 13 Oct 2005 11:41:53 +0900
"Trans" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Groovy be used in an applet and/or can it generate the Java bytecodes that then can be used in an applet? Casey Hawthorne Java 1 03-18-2009 12:56 AM
Word Docs Won't Open, Can't Be E-Mailed, Can't Be Deleted, Can't Be Copied, Etc. Martin Computer Support 16 02-24-2009 07:35 PM
Wireless can get internet but can't see network -- can when wired 02befree Computer Support 0 12-24-2007 09:10 PM
SOLVED - can't open file in windows media player / WMP. But can in VLC - video LAN .. Now can in WMP jameshanley39@yahoo.co.uk Computer Information 2 09-19-2007 02:53 AM
Windows can see mapped drives, but applications can't? =?Utf-8?B?RGFuaWVsIEVpY2hvcm4=?= Wireless Networking 3 11-18-2004 11:03 PM



Advertisments