Methods with different signatures

Hi!

There was a thread about a little typechecking to ruby.
What’s the status of this?

I expect something like:

So I can add handling different types without massing up other
definitions.

def doSomething(a:String)

end

def doSomething(a:Numeric)

end

···


±[ Kontra, Gergelykgergely@mcl.hu PhD student Room IB113 ]---------+

http://www.mcl.hu/~kgergely “Olyan langesz vagyok, hogy |
Mobil:(+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom” |
±- Magyar php mirror es magyar php dokumentacio: http://hu.php.net --+

Hi –

···

On Fri, 9 May 2003, KONTRA Gergely wrote:

Hi!

There was a thread about a little typechecking to ruby.
What’s the status of this?

I expect something like:

So I can add handling different types without massing up other
definitions.

def doSomething(a:String)

end

def doSomething(a:Numeric)

end

There have been many threads, and many, many posts about this. (And a
few about camelCase :slight_smile: Check the archive at
http://www.ruby-talk.org.

David


David Alan Black
home: dblack@superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

You’ll either have to use explicit kind_of?()-tests in the code, or use
something like the “Double Dispatch” design pattern to solve that kind
of problems. (Even though it would be kind of cool if we hade a feature
like that).

/Anders

···

— KONTRA Gergely kgergely@mlabdial.hit.bme.hu wrote:

def doSomething(a:String)

end

def doSomething(a:Numeric)

end

=====


Anders Bengtsson ndrsbngtssn@yahoo.se
Stockholm, Sweden


Gå före i kön och få din sajt värderad på nolltid med Yahoo! Express
Se mer på: http://se.docs.yahoo.com/info/express/help/index.html

There was an article on the wiki. Unfortunately I can’t find it any more.
The quintessence was to use an approach like this:

def doSomething(*args)
types = args.map {|arg| arg.class }

case types
when [String]
# string code here
when [Numeric]
# numeric code here
else
raise “Illegal argument types: #{ types }”
end
end

This works fine with multiple arguments.

robert

PS: Found it: http://www.rubygarden.org/ruby?RubyFromCpp

“KONTRA Gergely” kgergely@mlabdial.hit.bme.hu schrieb im Newsbeitrag
news:20030509113254.GA3102@mlabdial.hit.bme.hu…

···

Hi!

There was a thread about a little typechecking to ruby.
What’s the status of this?

I expect something like:

So I can add handling different types without massing up other
definitions.

def doSomething(a:String)

end

def doSomething(a:Numeric)

end


±[ Kontra, Gergelykgergely@mcl.hu PhD student Room IB113 ]---------+

http://www.mcl.hu/~kgergely “Olyan langesz vagyok, hogy |
Mobil:(+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom” |
±- Magyar php mirror es magyar php dokumentacio: http://hu.php.net --+

I wrote a little module for just this. Check out ‘StrongTyping’ on
RAA:

http://raa.ruby-lang.org/list.rhtml?name=strongtyping

You can do this:

def fn(*args)
    overload(args, String, String) {
        ...
    }

    overload(args, Integer, Integer) {
        ...
    }

    overload_default args        
end

This dispatches properly on ‘args’, otherwise gives an error. You
can also use it on single functions:

def fn2(a, b, c)
    expect(a, String, b, Symbol, c, String)
    ...
end

as well as being able to query a function for its types, etc.
HTH,

···

On Fri, 9 May 2003 20:32:58 +0900 KONTRA Gergely kgergely@mlabdial.hit.bme.hu wrote:

Hi!

There was a thread about a little typechecking to ruby.
What’s the status of this?

Ryan Pavlik rpav@users.sf.net

“Why do I even try to share my fabulous wit with you?” - 8BT

promising project. Is there a new release date?

Regards,

Peter

···

You wrote on the StrongTyping page you developed this for Mephle. And some while ago you were close on releasing the first version of Mephle on RAA. Unfortunately it’s still not there… :confused: It sounds like a very

Actually I haven’t announced it yet (for the reason I want to set
up mephle.org, running Mephle, and that requires ACLs, which are
about 3/4 of the way done). However you can download it:

http://www.nwlink.com/~rpav/mephle-0.7.0.tar.gz

This is slightly out-of-date, and you may have trouble with the
latest CVS CGI module if you try to use the html interface, but
you can consider it a sneak preview. :wink: Look for an official
annoucement Real Soon Now™.

···

On Sat, 10 May 2003 03:41:30 +0900 Nospam news-1@nospam.no-nonsense.org wrote:

You wrote on the StrongTyping page you developed this for Mephle. And > some while ago you were close on releasing the first version of Mephle > on RAA. Unfortunately it’s still not there… :confused: It sounds like a very
promising project. Is there a new release date?


Ryan Pavlik rpav@users.sf.net

“Why do I even try to share my fabulous wit with you?” - 8BT