On Fri, 28 Jan 2005 21:42:00 +0900, leon breedt <bitserf / gmail.com>
wrote:
> On Fri, 28 Jan 2005 12:16:34 +0900, Austin Ziegler
> <halostatue / gmail.com > wrote:
>> Frankly, adding static typing or even type hinting to Ruby will
>> *reduce* Ruby's flexibility.
> One of the areas where hinting (if I understand what you mean
> correctly by it) can be useful is for interoperability with more
> static platforms.

That is what I meant by it, and that is the only place that I think
that it's useful. That's not to say that it's the only place, but
it's the only place that I find such utility.

However, type hinting for the purpose of improving Ruby (either
performance or programmer "safety") would be useless. IMO.

> It does happen, ask those of us who use Ruby to provide WSDL/SOAP
> services to other platforms :)

This could theoretically be done with a bit of extra typing, similar
to what you've done with your Webservice module. However, it can be
improved:

  module Webservice
    def wsdl(options = {})
      if options[:method]
        op = { :in => options[:in], :out => options[:out] }
        (@__wsdl_cache[options[:method]] ||= []) << op
      else
        (@__wsdl_cache ||= []) << options
      end
    end

    def method_added(method)
      @__wsdl_definitions ||= {}
      @__wsdl_definitions[method] ||= []
      @__wsdl_cache.each do |options|
        @__wsdl_definitions[method] << options
      end
      @__wsdl_cache.clear
    end

    def self.extended(mod)
      class << mod
        define_method(:wsdl_definitions) { || @__wsdl_definitions }
      end
    end
  end

  class WebApi
    extend Webservice

    wsdl :in => [ String, Integer ], :out => [ String ]
    wsdl :in => [ Integer, String ], :out => [ String ]
    def meth(param1, param2)
      ""
    end

    wsdl :in => [ String ], :out => [ Integer ]
    def atoi(str)
      str.to_i
    end

    wsdl :method => :meth, :in => [ String, Float ],
         :out => [ String ]
  end

  puts WebApi.wsdl_definitions.inspect

What I'd recommend doing, even, is using symbols or some other way
of expressing a type or class, e.g., :String, not String. But the
above should simplify your WSDL generation.

-austin
-- 
Austin Ziegler * halostatue / gmail.com
               * Alternate: austin / halostatue.ca