[#4745] Win32: Ruby & APR; build problems for Ruby Subversion SWIG bindings — Erik Huelsmann <ehuels@...>

Having taken upon me the task to provide a Windows build for

24 messages 2005/04/20
[#4746] Re: Win32: Ruby & APR; build problems for Ruby Subversion SWIG bindings — Austin Ziegler <halostatue@...> 2005/04/20

On 4/20/05, Erik Huelsmann <ehuels@gmail.com> wrote:

[#4747] Re: Win32: Ruby & APR; build problems for Ruby Subversion SWIG bindings — Erik Huelsmann <ehuels@...> 2005/04/20

Hi Austin,

[#4762] Re: Win32: Ruby & APR; build problems for Ruby Subversion SWIG bindings — nobu.nokada@... 2005/04/24

Hi,

[#4783] Re: Win32: Ruby & APR; build problems for Ruby Subversion SWIG bindings — Erik Huelsmann <ehuels@...> 2005/04/25

On 4/24/05, nobu.nokada@softhome.net <nobu.nokada@softhome.net> wrote:

[#4787] Re: Win32: Ruby & APR; build problems for Ruby Subversion SWIG bindings — nobu.nokada@... 2005/04/25

Hi,

[#4794] Re: Win32: Ruby & APR; build problems for Ruby Subversion SWIG bindings — Erik Huelsmann <ehuels@...> 2005/04/25

> > > Ruby is just using AC_TYPE_UID_T. So, using typedef for them,

[#4751] Illegal regexp causes segfault — Andrew Walrond <andrew@...>

irb(main):058:0> a = /\[([^]]*)\]/

13 messages 2005/04/22

Extending a SimpleDelegator

From: TRANS <transfire@...>
Date: 2005-04-25 14:39:35 UTC
List: ruby-core #4790
I noticed that Delegator (delegate.rb) does not work as one might
expect when extending the delegator.

  require 'delegate'

  M = Module.new {
    def bracket ; p "come on" ; end
  }

  class SD < SimpleDelegator
    def initialize( obj )
      super( obj )
      extend M
    end
  end

  class C
    def bracket ;  p "hello" ;  end
  end

  c = C.new
  sd = SD.new(c)
  sd.bracket

This produces "hello" and not "come on".

I brought it up on ruby-talk. It was suggested by Cristoph that,
during initialization of the delegator, rather then define singleton
methods directly, the delegator could instead extend with an anonymous
module with those methods defined in it, which solves the problem:

  def initialize(obj)
    preserved = ::Kernel.public_instance_methods(false)
    preserved -= ["to_s","to_a","inspect","==","=~","==="]
    for t in self.class.ancestors
      preserved |= t.public_instance_methods(false)
      preserved |= t.private_instance_methods(false)
      preserved |= t.protected_instance_methods(false)
      break if t == Delegator
    end
    preserved << "singleton_method_added"
    proxy = Module.new
    for method in obj.methods
      next if preserved.include? method
      begin
	proxy.module_eval <<-EOS
	  def #{method}(*args, &block)
	    begin
	      __getobj__.__send__(:#{method}, *args, &block)
	    rescue Exception
	      $@.delete_if{|s| /:in `__getobj__'$/ =~ s} #`
	      $@.delete_if{|s| /^\\(eval\\):/ =~ s}
	      Kernel::raise
	    end
	  end
	EOS
      rescue SyntaxError
        raise NameError, "invalid identifier %s" % method, caller(4)
      end
    end
    extend proxy
  end

Of course this might have other repercussions I am unaware-of. But I
thought I should at least offer it up for consideration.

Thanks,
T.


In This Thread

Prev Next