From: Sam McCall Date: 2004-09-08T18:00:13+09:00 Subject: Re: [RCR] Unified type conversion framework Cool! Occasionally I think about doing something like this, so I can have some nice way to remember the custom conversions I use. Maybe you could sneak some extra conversions in with it, like [[1,2],[3,4]].as Hash # => {1=>2,3=>4} Related to this is type-checking when you do want it (duck typing is good, but I'd give it up in some cases to have an easy, readable way of checking that I'm not passing a hash instead of an array). I'd really like to be able to do: def method(foo,bar) foo.is! Hash bar.can_be! Array #... end where they do something like def is! t raise TypeError.new("Expected a #{t} but got a " + "#{self.type}: #{self.inspect}") unless is_a? t end def can_be! t raise TypeError.new("Can't convert to #{t} from "+ "#{self.type}: #{self.inspect}") unless can_be? t end And can_be? is the does-this-conversion-exist method. This might even be rdoc-able, if it was at the top of a method. It'd certainly make the ad-hoc documentation I write today executable. Sam