Comment

Comment by kayodelycaon

Code blocks. You don’t use a for loop, you call Array#each. On top of that, Ruby’s Enumerable module allows any object with an each method to access a whole bunch of convenience methods.

Note, the # means instance method when discussing ruby code. It’s not valid syntax.

Ruby allows you to be extremely concise, while maintaining readability for anyone moderately familiar with the language. In a way Perl is most definitely not.

Short example:

    arr = [<blog posts objects>]
    
    # Author may be nil
    number_of_authors = arr.map(&:author).compact.uniq.count
You can imagine how easy it is to throw data around with very little code. Loops are abstracted, so you never think about them as loops. Instead you just see data moving around.

Edit: A few languages (like JavaScript) implement this behavior explicitly by passing anonymous functions as callbacks.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton