From: "Florian Groß" Date: 2005-09-16T04:31:44+09:00 Subject: Re: you can't get in trouble with your boss for picking C# Trans wrote: >>True, this is not possible just yet, but C# 2 already introduced >>features like yield return and delegate(int x) { return x * 2; } that >>are a huge step away from the simple mindedness of Java. > > Had to do it. > > require 'blankslate' > > class Delegate < BlankSlate > def initialize( obj, &yld ) > @obj = obj > @yld = yld > end > def method_missing( sym, *args, &blk ) > if @yld > @yld[ @obj ].__send__( sym, *args, &blk ) > else > @obj.__send__( sym, *args, &blk ) > end > end > end Careful! C# delegates don't actually delegate messages. Instead they are the closest thing to Ruby's blocks the language has right now. Not sure why they named them that way, but it's probably related to the implementation.