From: Chad Lester Date: 2007-03-16T04:13:13+09:00 Subject: Re: When introspection doesn't... Eden, Thanks a million. You've definitely solved this mystery for me. I wouldn't have thought that they would explicitly redefined the 'class' method, but they did because it was just the easiest thing to do... I gave myself a little homework assignment and wrote a very small program that demonstrates how easy it is to do this. I learned about undef_method and method_missing (which probably should be in the FAQ about how Ruby decides which method gets called). Hey, you should get compensated for this. I'll send ya 50 bucks if you tell me how. :) same user name at gmail. Also... it does kind of make wish there were some methods that one could not override, just so you can poke in and see what's going on without resorting to c programming. Or maybe this would be better done with a special inspector object that knows how to inspect objects... I'll look for one, and then maybe write one if I can't find anything. Here's my little example, based on Eden's help: --------------------------- class Proxy instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_)/ } def initialize(target) @target = target end def method_missing(method, *args, &block) # most messages just get routed to the target @target.send(method, *args, &block) end def find_all(*args, &block) # super-secret find_all that completely ignores block! @target end end a = [1,2,3,4,5,6] p = Proxy.new(a) puts p.class puts p.method(:find_all) my_block = Proc.new { |x| x % 2 == 0 } puts (p.find_all &my_block).inspect puts (p.method(:find_all).call &my_block).inspect if p.class == Array Array.instance_method(:find_all).bind(p) end Output looks like: Array # [1, 2, 3, 4, 5, 6] [2, 4, 6] ./proxy_fun.rb:32:in `bind': bind argument must be an instance of Array (TypeError) from ./proxy_fun.rb:32 -- Posted via http://www.ruby-forum.com/.