Ruby Under a Microscope: An Illustrated Guide to Ruby Internals by Pat Shaughnessy
Author:Pat Shaughnessy
Language: eng
Format: mobi, pdf
Tags: COMPUTERS / Programming Languages / Ruby
ISBN: 9781593275617
Publisher: No Starch Press
Published: 2013-11-06T16:00:00+00:00
Chapter 8. How Ruby Borrowed a Decades-Old Idea from Lisp
Blocks are Ruby’s implementation of closures.
Blocks are one of the most commonly used and powerful features of Ruby because they allow you to pass a code snippet to Enumerable methods, such as each, detect, or inject. Using the yield keyword, you can also write your own custom iterators or functions that call blocks for other reasons. Ruby code containing blocks is often more succinct, elegant, and expressive than equivalent code in older languages, such as C.
But don’t jump to the conclusion that blocks are a new idea! In fact, blocks are not new to Ruby at all. The computer science concept behind blocks, called closures, was first invented by Peter J. Landin in 1964, a few years after the original version of Lisp was created by John McCarthy in 1958. Closures were later adopted by Lisp, or — more precisely — a dialect of Lisp called Scheme, which was invented by Gerald Sussman and Guy Steele in 1975. Sussman and Steele’s use of closures in Scheme brought the idea to many programmers for the first time.
But what does the word closure actually mean in this context? In other words, exactly what are Ruby blocks? Are they just the snippet of Ruby code that appears between the do and end keywords? In this chapter I’ll review how Ruby implements blocks internally and demonstrate how they meet the definition of closure used by Sussman and Steele back in 1975. I’ll also show how blocks, lambdas, and procs are all different ways of looking at closures.
Download
Ruby Under a Microscope: An Illustrated Guide to Ruby Internals by Pat Shaughnessy.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9914)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9795)
The Mikado Method by Ola Ellnestam Daniel Brolund(9777)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8295)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7778)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Windows APT Warfare by Sheng-Hao Ma(6823)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6553)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6419)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Kotlin in Action by Dmitry Jemerov(5062)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4316)
Functional Programming in JavaScript by Mantyla Dan(4038)
Solidity Programming Essentials by Ritesh Modi(3994)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3785)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3729)
The Ultimate iOS Interview Playbook by Avi Tsadok(3704)
