C# · Dotnet · Linux · Ruby

Delegates similarity in Ruby and csharp

Dear Reader,

It’s quite amazing to me today that when i was reading Delegates concept in Ruby. The Syntax, and working(execution style) is almost similar i can say. I guess this is one of those situations you might say for yourself AHA!

I am very well versed and used many times delegates in C# and so when i started the topic of similar in Ruby today i was quite amazed to learn that it almost looks similar and if your like me, will surely fall in love with ruby as you did with C#.

Of course this post is not about C# vs Ruby. It’s about those similarities which benefits and surprises developers like me who wish to earn different languages all together.

So just to give you the big picture, here is the below code:

prc = lambda {puts 'Hello'}
# method call invokes the block
prc.call

As you can see above, this almost looks the same as the C# equivalent of anonymous delegates which is as shown below:

Action myDel = () => Console.WriteLine("Hello");
myDel();

That’s all my friend, i just wanted to share my AHA surprise moments with you. Hope you liked it.
As always, your valuable comments are much appreciated and helpful for my learning.

Thanks,
Happy Coding 🙂

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s