From: tho_mica_l Date: 2008-02-08T14:30:02+09:00 Subject: Re: Ruby type-safe? Ruby strongly/weakly typed? Ruby pitfalls? > Thought it was interesting. So you can easily add type checking to > your functions if you desire to do so. Well, there are various way to add something in this line to the language. E.g., one could easily do something like this: class Class def let(value) unless self === value raise TypeError, 'expected %s but got %s' % [self.name, value.class.name] end value end end irb(main)> String.let a = 1 TypeError: expected String but got Fixnum irb(main)> String.let a = "foo" => "foo" But the idea of type definitions and argument checks would of course be to give the compiler/interpreter a chance to perform some sanity checks at load/compile time. For this to happen, ruby would have to understand these definitions though and try to make some sense out of them. Now I know the counter-arguments since this isn't the first time this was discussed. I nevertheless wish that ruby had some sense for types/interfaces and from time to time I take the freedom to write this. Thomas.