Around the Ruby Block
summary
Shows why a nested-RSpec let value unexpectedly becomes invisible inside an inner block: let creates a helper method, instance_eval-like calls change self, and that combination makes the inner block look on the wrong receiver rather than the outer local scope. Explains Ruby internals with C structs like RB_block_t and how the environment pointer ladder implements dynamic variable lookup. Demonstrates that lambdas allocate a heap copy so a lambda copies stack frame preserves locals, and benchmarks show block usage costing ~50% (up to ~71%) and find/lamda-made methods running about twice as slow.
AI-written summary · about
chapters (11)
- 0:00Introduction to Ruby blocks
- 3:54Understanding block closures
- 11:57Dynamic variable access in blocks
- 13:22Self and scope in blocks
- 18:19DEF vs define_method
- 20:45Performance cost of blocks
- 22:35Lambdas and procs explained
- 27:58Memory impact of lambdas
- 30:52Binding objects and eval
- 32:17define_method and lambdas
- 35:05Conclusion and resources








