On Wed, 31 Aug 2005, Peter Vanbroekhoven wrote:

> On Tue, 30 Aug 2005, David A. Black wrote:
>
>> I see what you mean; it's very magic.  I can't think of a way to
>> implement it in Ruby, and even though someone will be able to with dl
>> or whatever, it will still be too magic :-)
>
> Actually... Here's an implementation using the very thing that started this 
> thread:
>
>  class Object
>    private :send
>    def method_missing(m, *args, &blk)
>      if m == :send
>        eval "self.#{args[0]}(*args[1..-1], &blk)"
>      else
>        eval "#{m}(*args, &blk)"
>      end
>    end
>  end
>
>  class A
>    def do_sth
>      puts "hello"
>    end
>    private :do_sth
>  end
>
>  A.new.instance_eval { do_sth } # => prints "hello"
>  A.new.do_sth # => raises NoMethodError

OK, pasted the wrong version... Here goes another try:

   class Object
     private :send
     def method_missing(m, *args, &blk)
       if m == :send
         eval "self.#{args[0]}(*args[1..-1], &blk)"
       else
         super
       end
     end
   end

   class A
     def do_sth
       puts "hello"
     end
     private :do_sth
   end

   A.new.instance_eval { send(:do_sth) } # => prints "hello"
   A.new.send(:do_sth) # => raises NoMethodError

Peter