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
Since I have superseded the proposal I made just a few hours ago, I will repeat my short comment to it here:
<quote> 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* </quote>
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
Back to RCRchive.
RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog