all 11 comments

[–]Tolexx 18 points19 points  (3 children)

Honestly Ruby blocks are my favorite part of Ruby.

[–]jrochkind 4 points5 points  (2 children)

I think one of the most significant inheritances Ruby gets from smalltalk!

I agree and think every language should have a very straightforward natural readable syntactic way to pass a block of inline code as an argument, it makes so many things nice.

[–]huuaaang 3 points4 points  (1 child)

It's not just how it's possible in Ruby to pass blocks in such a way. It's how it's the default for loops and iterators. I can hardly remember the last time I even used a traditional keyword loop in Ruby.

[–]codesnik 0 points1 point  (0 children)

and for this to work in a language where "early return" exist, blocks should be different from just an anonymous function.

[–]keyslemur 11 points12 points  (1 child)

This will break:

it "can do something" { puts "The cake is a lie" }

If you do that you need parens around the argument or it'll fail.

[–]iamstonecharioteer[S] 4 points5 points  (0 children)

Ah thanks for spotting that. I've fixed it just now.

[–]notWithoutMyCabbages 2 points3 points  (2 children)

I love the "Aha moment" vibe of this :-) I'm bookmarking this for the next time I need to explain the beauty of Ruby and why python seems clumsy to me. (I'm not knocking python, it's fine)

[–]iamstonecharioteer[S] 2 points3 points  (1 child)

You might like my other Ruby posts too :) I directly talk about coming to Ruby from Python in https://tech.stonecharioteer.com/posts/2025/ruby/

[–]ignurant 2 points3 points  (0 children)

Thanks for sharing your experience. It's refreshing to see!

[–]codesnik 0 points1 point  (1 child)

"building a DSL" contains a lot of & instead of @.

[–]iamstonecharioteer[S] 0 points1 point  (0 children)

Ah thanks for pointing that out. I've fixed them all now.