From: Robert Feldt Date: 2001-06-27T16:08:26+09:00 Subject: [ruby-talk:16953] Re: Method overloading (option) Was: Re: On Wed, 27 Jun 2001, Avi Bryant wrote: > Hmmm... > Aspects are for separating out orthogonal concerns; type-checking, > although not exactly integral to most code, can't be cleanly > separated from it either, since type declarations are best kept with the > types. I can imagine an aspect that took a naming convention, like > foo(aString), and wove in code to enforce the implicit types, but I don't > think it would be that useful unless that naming convention were followed > quite strictly. > I'm also a bit skeptical as to the value of all this even if there are probably a handful ways one can think of doing it. One might be: typed_def :your_bizarre_method, Integer do |length| length + 1 end typed_def :your_bizarre_method, String do |string| string.length + 1 end but I'm unsure what it would add compared to Matjus proposals. With a RubyInRuby parser we could of course have a nicer syntax by preprocessing the code def your_bizarre_method(Integer length) length + 1 end def your_bizarre_method(String string) string.length + 1 end into def your_bizarre_method(a1) if a1.kind_of?(Integer) ... elsif a1.kind_of?(String) ... end end but I don't think this is common enough to motivate the expenses... /Robert