From: gabriele renzi Date: 2003-11-18T18:37:16+09:00 Subject: Re: Strong Typing (Re: Managing metadata about attribute types) il Tue, 18 Nov 2003 06:06:18 GMT, Thien Vuong ha scritto:: > > > From my limited understanding, there are 2 types of checking that could >be used: respond_to? (duck-typing?) and kind_of? By Ruby dynamism, >none of the current method could guarantee the behaviour. So we're >have some choices: > >- Respond_to? is fine. It works for a large class of problems where one > or 2 methods are good enough to define the behaviour. In fact, for > those, a type/class contortion is overkill and having this capability > on Ruby is great. >- kind_of?, which to me, is a combination of respond_to? with the > expected behaviour of the class. It comes at a cost that the object > does need to be in the correct class hiearchy. >- A very flexible behaviour model based on respond_to? This is great, > but requires extra coding, could be buggy, and have > performance impact. let me put my 2eurocent.. a model I'd like to see is: (for #1) type hints in method arguments: def m(String s, b) at compile time ruby would work like putting an extra a.kind_of? String at tht top of m(). (for #2) a new Kernel method like def m(a,b) type_check(a) the type_check would work like: "hey, compiler, each time you see 'a' responding to :metod put an additional a.respond_to? :metod at the top of m()" Obviously if we could find a method name withless than 7 letters everybody would start to use it. btw with some black magic we could even have a better def m(TypeCheck a,b) .... Anyway this mail was just to ask: how is the #3 model you're proposing supposed to work?