Home / Companies / New Relic / Blog / Post Details
Content Deep Dive

Weird Ruby Part 1: The Beginning of the End

Blog post from New Relic

Post Details
Company
Date Published
Author
Jonan Scheffler
Word Count
1,124
Language
English
Hacker News Points
-
Summary

This blog post, the first in a series on "Weird Ruby," explores the peculiar and often counterintuitive behaviors of the Ruby programming language, particularly the use of begin-end blocks and their interaction with conditionals. The author, inspired by insights gained from speaking at the Keep Ruby Weird conference, aims to offer an alternative perspective on these behaviors rather than just listing surprising Ruby code samples. The post illustrates that while standalone begin-end blocks do not change code behavior, when combined with constructs like while, they can lead to unexpected results due to Ruby's do-while loop construct. This loop allows the code within the begin-end block to execute at least once before checking the condition, a behavior that even the language's creator, Matz, has expressed regret over, suggesting a more intuitive loop-break construct. The author encourages readers to engage with Ruby's TracePoint feature for deeper exploration, while cautioning against its use in production environments due to potential performance issues.