Submitted by Icekiss (Sat Mar 27 18:03:19 UTC 2004)
Add a new instance method rekursive_index to the module Enumerable.Interface:
rekursive_index(key) -> anArray<br>This method would return an array, that contains the indexes of the Enumerables necessary to reach the key.
module Enumerable
def rekursive_index(key) each_with_index do |element, index| return [index] if element==key #if element. if element.kind_of?(Enumerable) rIndex=element.rekursive_index(key) return [index]+rIndex if rIndex end end return nil end
end
Comments | Current voting | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
This RCR supersedes RCR 235.
RCRchive copyright © David Alan Black, 2003-2005.
Powered by .
Since I have superseded the proposal I made just a few hours ago, I will repeat my short comment to it here:
I have discovered ruby 3 days ago, and I have to say: It is absolutely the best programming language I have ever seen. Just thought I share what usefull additions to the standard classes I can see. :-)
And a deep bow to matz for making this language available. *bow*
The reason I superseded is obvious: It should of course be implemented on the level of enumberation. Is it called a module instance method? "Programming Ruby" contradicts itself on the naming...
--Icekiss
I'm getting a bit confused: I reread the list of methods implemented by the various classes: Lots of things that could be done for every enumerable (e.g index) are implemented only for arrays. Any reason for this? To implement this proposal only for arrays, just replace:
module Enumerable
with
class Array
and
if element.kind_of?(Enumerable)
with
if element.kind_of?(Array)
--Icekiss
Icekiss, you might want to slow down and keep studying and learning about Ruby for a while. There's no shame attached to taking more than three days to suggest languages changes :-) You can ask questions, and learn a lot, on the ruby-talk mailing list and also on the IRC channel #ruby-lang, on irc.freenode.net. -- David Black