365 reasons to love ruby

David made this website as a challenge to himself: post a reason I love Ruby every day for a whole year - 365 reasons to love Ruby!

His hope is for this work to rekindle the love other Ruby programmers have for this language, and inspire those who are curious or even on the fence about it to jump in and give it a go.

Check it out using the below links:

6 Likes

Love it!

but there are more than 365 reasons to love Ruby :sweat_smile:

1 Like

I’m surprised “method_missing” hasn’t been mention. There’s so much magic you can do with that.

It might come up still a lot of days to go :slight_smile: … What’s your favourite use case of method_missing?

A couple of cases. First is ActiveRecord. In the past, classes that provided access to a database table had to be modified / regenerated every time you modified the table. ActiveRecord doesn’t need to implement a method for each field, it just catches your request with method missing and looks to see if that field exists.

Second is drb (Distributed Ruby). Normally a remote procedure call has to be implemented in both the remote object and the local caller. Method missing allows the caller to not know anything about which methods the remote object implements. It simply catches any call to itself and sends the method name as a symbol and all arguments to the remote object. If the remote object doesn’t implement that method it sends back an exception. If it does implement it, it sends back the result. So you can modify the remote object and add methods without ever having to modify the local object.

1 Like

I haven’t done any meta programming articles as of yet. I’ll probably do a “meta programming week” at some point and will definitely write about method_missing.

method_missing has some significant drawbacks as well though. The main issue with not calling pre-defined methods in general is debugging since we don’t get backtraces pointing back to an actual place in the source code.

2 Likes

I have a feeling I’m going to start having a hard time finding things I’m seriously passionate about between 100-150 reasons. 365 is a stretch to be honest :sweat_smile:

365 are def a lot! But great work with the 60+ you’ve compiled so far. I’ve learned some things I didn’t knew before…

Looking forward to the meta programming week :slight_smile:. Also the latest File.read is a great example of Ruby expressiveness.