From: "Mauricio Fernández" Date: 2003-02-05T06:00:43+09:00 Subject: Re: [contest] Code challenge On Wed, Feb 05, 2003 at 05:01:28AM +0900, Yukihiro Matsumoto wrote: > Hi, > > In message "[contest] Code challenge" > on 03/02/05, Mauricio Fern�ndez writes: > > | You are expected to subclass Unbreakable::A and find a way to override > | method #a. Normally all your code should be in the indicated position. > | Class B must be directly derived from Unbreakable::A. The following is > | not a valid solution: > |class B > | def a; puts "You won!"; end > | def kind_of? a > | true > | end > |end > | > | Warning > | > | This mission is, to the best of my current knowledge, impossible. > > Is this a valid answer? > > class B < Unbreakable::A > def a; puts "You won!"; end > # PUT YOUR CODE HERE! > p Unbreakable::A.instance_eval{@no_override.clear} > def a; puts "You won!"; end > end I guess yes. To be honest I thought of that but either overlooked its potential or forgot to freeze the class iv. (can't remember) :-) Wish I could say I left it as a back-door, but that is not the case. But now, what happens if I do: ... def no_redef(*args) @no_override ||= [] args.each { |i| @no_override << i } @no_override.freeze end ... Is it impossible enough now? ;-) My ultimate goal with this contest is seeing if it is at all possible to prevent redefinition unconditionally, against all attacks. And I learn a great deal along the way, too. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Never make any mistaeks. -- Anonymous, in a mail discussion about to a kernel bug report