On 09/02/2009, David Masover <ninja / slaphack.com> wrote:
>
> Either way, I would put the burden back on you. Why is this so dangerous?
> Why is it any more dangerous than the other duck typing tricks Rubyists use
> every day? Why shouldn't I be able to do:
>
> a.method(:foo).unbind.bind(b)
>
> when a and b aren't related, but I happen to know they share a common
> theme? After all, what ties the method to the object -- isn't it mostly
> going to be calling instance methods, and occasionally accessing instance
> variables -- so why should 'self' be exempted from the "quacks like" rule?
>
Actually you sort of can except the binding is not permanent.
module Kernel
module Q175
Require = Kernel.instance_method :require
def scan
...
end
end
undef_method :require
def require file
loc = Q175::scan file
res = Q175::Require.bind(self).call file
STDERR.puts "require: #{file} => #{loc}" if res && loc
res
end
end
Thanks
Michal