From: Ralph Mason Date: 2001-11-22T06:59:48+09:00 Subject: [ruby-talk:26079] Re: call_myself Your right about the argument count. Here is a perhaps useful use for this ( useful use, an interesting phrase) def call_type_self(*y) caller[-2] =~/(\w*)'/ send(y[0].type.to_s + '_' + $1.to_s ,*y) end def polyfunc(x) call_type_self(x) end def String_polyfunc(x) #use string end def Fixnum_polyfunc(x) #use num end On the regex stuff. I'm still learning too. Ralph Kent Dahl wrote: > > While I don't agree that call_self is of use. > > Arg! You beat me to it, since I can't tell heads nor tails of RegExps > ;-) > > But anyway, wouldn't your solution only handle single argument > functions? > > *runs off, steals Ralph's code, adds 2 asterisk and chucks it in Kernel > instead* > > > module Kernel > def call_myself( *a ) > caller[-2] =~/(\w*)'/ > send( $1, *a ) > end > end > > def fact(n) > if n == 0 > 1 > else > n * call_myself(n-1) > end > end > > puts fact(5) >