2007/11/15, Keith Chapman <keithgchapman / gmail.com>:
> Hi Robert and others,
>
> We are trying to define a way of writing web services in ruby (Code
> First approach). And we expect to keep it as simple as possible. In
> order to do this we need to define some metadata that we can use to
> generate a pleasant WSDL. This metadata may include things like
> documentation and details about input and output Types. Note that ruby
> is a Dynamic language whereas xml schema is not. And although a
> parameter taken into a function could be of anyType in most cases it
> operates on it assuming its of a certain type. And getting this
> information into the WSDL matters in that case.
>
> Assume that I have a function as follows,
>
> def foo(bar, foobar)
>
>   end
>
> I need to get the information on the types expected by this function
> across to the WSDL. I basically need a way to say that bar is a String
> and foobar is an integer. This is where the matadata that I'm talking
> about comes into play.
>
> It will be nice if the Ruby community can help us figure out a nice
> rubish way of doing this. The most important thing is that I want this
> all to fit in with ruby people so this should look rubish as much as
> possible.

Well, then it sounds as if you need structured data for a method.
Extending my last proposed solution a bit you could do this:

16:08:14 /cygdrive/c$ cat meta.rb
require 'ostruct'

class Foo
 def self.meta()
   @method_meta ||= Hash.new {|h,k| h[k]=OpenStruct.new}
 end

 def bar() 1 end

 meta[:bar].length=567
 meta[:bar].return_type=Integer
end

puts Foo.meta[:bar]
16:08:48 /cygdrive/c$ ruby meta.rb
#<OpenStruct return_type=Integer, length=567>
16:08:50 /cygdrive/c$

Of course you can use a Hash instead of the OpenStruct - but that's
probably rather a matter of taste.  If you need automatic discovery of
meta data set I'd probably rather use a Hash - if you know which meta
data you expect I'd probably use an OpenStruct or a Struct.

Cheers

robert

-- 
use.inject do |as, often| as.you_can - without end