def self::install_delegator_proxy( klass, langcode )
raise ArgumentError, "Missing langcode" if langcode.nil?
if klass.instance_methods( false ).include?( "method_missing" )
klass.module_eval %{
alias_method :__orig_method_missing, :method_missing
}
end
klass.module_eval %{
def method_missing( sym, *args, &block )
# If the linguistic delegator answers the message, install a
# delegator method and call it.
if self.send( :#{langcode} ).respond_to?( sym )
# $stderr.puts "Installing linguistic delegator method \#{sym} " \
# "for the '#{langcode}' proxy"
self.class.module_eval %{
def \#{sym}( *args, &block )
self.#{langcode}.\#{sym}( *args, &block )
end
}
self.method( sym ).call( *args, &block )
# Otherwise either call the overridden proxy method if there is
# one, or just let our parent deal with it.
else
if self.respond_to?( :__orig_method_missing )
return self.__orig_method_missing( sym, *args, &block )
else
super( sym, *args, &block )
end
end
end
}
end