Dissecting a Ruby Block
summary
Code-level claim: a Ruby block is a closure — a compiled instruction sequence plus its referencing environment — implemented in MRI C by an rb_block that stores an iseq pointer and a dfp (dynamic frame pointer) (and a cell/self pointer). Experiments using VM stacks, control-frame copies and examples like 10.times yielding, lambda returning a proc (which copies the stack frame to the heap) and binding creating an rb_binding show procs, lambdas and blocks are the same mechanism and they work as described.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 4:24Study Ruby internals and closures
- 6:50Ruby block under microscope
- 11:45Ruby VM and block structure
- 17:43Blocks reference parent scope
- 22:39Blocks as closures and history
- 23:00Origins of lambda in Ruby
- 25:48Lambda converts blocks to objects
- 30:59Closures and metaprogramming
- 38:00Bindings and eval as closures
- 40:46Summary of Ruby closures








