The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Ruby until something better comes along

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Ruby until something better comes along Posted: Aug 8, 2006 11:54 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Ruby until something better comes along
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
And no, with all due respect to my Perl loving comrades, it's not Perl 6. Sydney maybe. Or some OO-functional hybrid that has yet to be invented. But I digress.

This post is really about multiple dispatch. Or, as I call it - "method overloading". Yes, I've trademarked that term. Don't try and use it in your own blogs without paying me a quarter first. But I digress, again.

Piers mentions Perl subroutine attributes. As far as I can tell, the main use for subroutine attributes is for multiple dispatch, er, method overloading. Probably using a module like Attribute::Handlers.

In fact, that's about the only way I was able to understand subroutine attributes in Perl. I found the primary documentation on attributes to be strangely obtuse and unhelpful. I still find it a bass-ackwards way of handling dispatch. I mean, when would you use Attribute::Handlers over, say, Class::Multimethod? Maybe I'm missing something. But I digress yet again.

Anyway, here are two approaches with Ruby. The first is Nobu's overload package:
require 'overload'

def foo(arg)
   ...
end
overload(:foo, String)

def foo(arg1, arg2)
   ...
end
overload(:foo, String, String)

The second uses Ryan Pavlik's strongtyping package.
require 'strongtyping'
include StrongTyping

def foo(*args)
overload(args, String){ |s1|
...
return
}

overload(args, String, String){ |s1, s2|
...
return
}

overload_error args
end
</pre>
Then there's the strongtyping behavior from Sydney:
require 'strongtypingbehavior'

def foo(String x)
   ...
end

def foo(String x, String y)
   ...
end

Nice, eh? Yes, this is a bit of a rehash of a previous post, but I'm feeling less skittish about adding strongtyping behavior as part of the Sydney stdlib.

Read: Ruby until something better comes along

Topic: More archeolinguistics: unearthing proto-Ruby Previous Topic   Next Topic Topic: Arrival in Bangalore

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use