Suggestion for the Ruby Learning Track (blocks and yield)

Hey everyone,
while working through the Ruby exercises for the 12in23, I’ve stumbled upon a topic that I find not enough emphasized in the learning track: blocks and yield. Up to now I’ve needed it twice for the solutions of some exercises; once in the list-ops exercise:

  def mapper(array, &block)
    result = []
    while not array.empty?
      result.push(yield(array.shift))
    end
    result
  end

And once in the binary search tree exercise, where part of the task is to implement the Bst#each method. I’m not sure if there are other exercises that also might profit from it (I’m just 50% through with the track). It’s of course easily searchable (at least if you know what you need to be looking for), but I still feel this should be a concept to learn in the learning path, as it is something essential to Ruby and something you don’t find in many other (or at least classic) programming languages?

Me myself, I found this page a really helpful resource on the topic. This also touches procs and lambdas, which I think could also be interesting for the Ruby learning track, but at least (up to now, that is) I didn’t need these concepts in the exercises, so I feel it’s not as necessary as a learning concept as blocks and yield are.

I’m interested in what you think, and as always: Thanks for all the great work you guys are doing with the site! All in all the Ruby learning track is really great and I am having a lot of fun with it as well as with the exercises! Thanks to everyone who participated in it!

2 Likes

Hi!

I have worked on adding some new concepts recently in the last 2 months have 2 new concepts been added to have a larger cover of the core datatypes and structures. Those 2 were symbols and ranges, both beneficial concepts. I have plans for plenty of more concepts, but they take time to write. My current main approach is to port Crystal-lang concept into Ruby which works well and saves time, but even though I am rather limited in time.

I recently made a roadmap so I could more clearly see when I plan new content (a picture for reference):

And I can confirm that Ruby concept 3, will very likely include case. But concept 4 might very well be procs/blocks, I have no plans for lamda though. If there is demand I could likely push procs/block to the middle of November.

As for implementing each so do you likely want to work with enumerable mixin: Module: Enumerable (Ruby 3.0.2) (ruby-doc.org).

2 Likes