On 29/06/06, Logan Capaldo <logancapaldo / gmail.com> wrote:
> trans was asking, if you wanted to use "super" why not just subclass
> them? Really, sometimes inheritance really is the solution.

Ah sorry I didn't understood it that way. This is not possible in my
situation. I'm using Camping. And Camping does funky stuff. It defines
a bunch of modules with class methods, etc.. trough evaling it's own
code. If you want to run a Camping app, you have to use the evaled
code.

> That said, the usual way to wrap a method like that is:
>
> class LegacyClass
>    alias original_version_of_some_method some_method
>    def some_method
>      ...
>      original_version_of_some_method(...) # effectively 'super'
>    end
> end

Hmm that seems to be feasible.

I've just had a devil idea :-D

class Cls4; end
class << Cls4
  def somemethod; "legacy"
end

mod = Module.new
mod.module_eval do
  define_method :somemethod, &Cls4.method(:somemethod).to_proc
end

Cls4.extend mod
class << Cls4
  def somemethod; super + " redefined !"; end
end

Cls4.somemethod #=> "legacy redefined !"


Thanks everybody :-)

-- 
Cheers,
  zimbatm

http://zimbatm.oree.ch