James [mailto:az / despammed.com] wrote:

//What would be a good ruby idiom to move efficiently from
//a positive integer in the range 0 to ~2000 to a specific
//method call?
//
//A case / when statement would do this simply, but in perl
//I sped this up by building a lookup table using
//an array containing references to the appropriate perl subs.

something like this?

C:\family\ruby>cat a1.rb
m=[]
m[0]="first_method"
m[1]="second_method"
m[2]="third_method"


def first_method
        p "i'm first"
end

def second_method
        p "i'm second :-)"
end

def third_method
        p "i'm third and i called them backed! :-)))"
        first_method
        second_method
end

m.each { |method|
  send method
}


C:\family\ruby>a1.rb
"i'm first"
"i'm second :-)"
"i'm third and i called them backed! :-)))"
"i'm first"
"i'm second :-)"


#i'm writing this w my son james at my back too :-)
#hth


//
//Best Wishes,
//James

kind regards -botp