[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Redef undef'ed methods?

Robert Feldt

3/31/2006 7:58:00 AM

How "final" is a call to undef_method? Is there any way to get the
method back, ie. hook it up to the class again?

From my understanding of the C code it seems impossible since the
function/method pointer is set to 0 and there is no way from Ruby to
access the original value for that pointer again (unless you have
extracted "it" earlier with one of the "*method" methods). Is this
analysis correct?

If so code like

module Kernel
[:eval, :system, :exec, :callcc, :`, # `
:set_trace_func, :sleep, :syscall].each do |m|
undef_method m
end
end

class Module
[:module_eval, :class_eval,
:define_method, :method, :instance_method,
:private_class_method].each do |m|
undef_method m
end
end

class Object
[:instance_eval].each {|m| undef_method m}
end

etc would give a possibility for a kind of simple, fine-grained
"sandboxing"? (I'm not implying you should do this instead of
tainting/SAFE-levels etc, just exploring possibilities)

Thanks,

Robert Feldt


4 Answers

Florian Groß

3/31/2006 2:00:00 PM

0

Robert Dober

3/31/2006 2:33:00 PM

0

On 3/31/06, Florian Groß <florgro@gmail.com> wrote:
>
>
>
>
> class A
alias_method :b, :a
undef_method :a
end

...

class A
alias_method :a, :b
end

Obviously I missed something ;)!

Cheers
Robert

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

Robert Feldt

3/31/2006 2:42:00 PM

0

On 3/31/06, Robert Dober <robert.dober@gmail.com> wrote:
> On 3/31/06, Florian Groß <florgro@gmail.com> wrote:
> >
> >
> >
> >
> > class A
> alias_method :b, :a
> undef_method :a
> end
>
> ...
>
> class A
> alias_method :a, :b
> end
>
> Obviously I missed something ;)!
>
Yes, that will work around. Also you can do it with define_method if
you have a handle to the undef'ed method. However, these "holes" can
be covered by undef'ing more methods (ie alias_method etc) so it might
still be a useful technique for some situations.

Thanks,

Robert Feldt


Florian Groß

3/31/2006 5:12:00 PM

0