Mastering Ruby Closures: A Guide to Blocks, Procs, and Lambdas
暫譯: 精通 Ruby 閉包:區塊、Proc 與 Lambda 的指南

Benjamin Tan Wei Hao

  • 出版商: Pragmatic Bookshelf
  • 出版日期: 2017-08-26
  • 售價: $900
  • 貴賓價: 9.5$855
  • 語言: 英文
  • 頁數: 96
  • 裝訂: Paperback
  • ISBN: 1680502611
  • ISBN-13: 9781680502619
  • 相關分類: Ruby
  • 立即出貨(限量) (庫存=4)

買這商品的人也買了...

商品描述

The road to Ruby mastery is paved with blocks, procs, and lambdas. To be a truly effective Ruby programmer, it's not enough just to understand these features - you need to know how to use them in practice. Discover how to write code that is elegant, expressive, and a joy to use, and gain a deep understanding of these concepts so you can work with third-party gems and libraries more easily. Whether you are completely new to Ruby or a seasoned Rubyist, you'll find good use for these concepts in your code.

Ruby developers use the Ruby language as the yardstick for expressivity, flexibility, and elegance - and a large part of this is due to blocks, lambdas, and procs. These language features make Ruby one of the most beautiful and pleasant languages to work with. Learn how to understand and craft code that will take you closer to Ruby mastery.

Start with the basics of closures and then dive into blocks, as you learn about the patterns that involve blocks, and how they are used in real-world code. Then create and use procs and lambdas. Finally, build your own lazy enumerables with advanced Ruby features such as fibers and generators. Along the way, work with computer science concepts such as closures, free variables and first-class functions. Spot a closure easily. Identify the patterns where you can effectively use blocks and re-implement common standard library methods using them. Trace through how Symbol#to_proc works and find out the different ways of calling procs. This succinct guide takes you through the different kinds of Ruby closures with engaging examples, and each chapter comes with exercises that test and challenge your understanding.

When you finish this book, blocks, procs, and lambdas will have become an integral part of your Ruby toolbox.

What You Need:Ruby 2.x and a basic familiarity with Ruby.

商品描述(中文翻譯)

道路通往 Ruby 精通的旅程充滿了 blocks、procs 和 lambdas。要成為一名真正有效的 Ruby 程式設計師,僅僅理解這些特性是不夠的——你需要知道如何在實踐中使用它們。發現如何編寫優雅、表達力強且令人愉悅的程式碼,深入理解這些概念,以便更輕鬆地使用第三方 gems 和庫。無論你是完全新手還是資深的 Ruby 使用者,你都會在程式碼中找到這些概念的良好應用。

Ruby 開發者將 Ruby 語言視為表達力、靈活性和優雅的標準——而這在很大程度上歸功於 blocks、lambdas 和 procs。這些語言特性使 Ruby 成為最美麗和愉快的語言之一。學習如何理解和編寫程式碼,讓你更接近 Ruby 的精通。

從閉包的基本概念開始,然後深入了解 blocks,學習涉及 blocks 的模式,以及它們在實際程式碼中的使用方式。接著創建和使用 procs 和 lambdas。最後,使用進階的 Ruby 特性如 fibers 和 generators,構建自己的懶惰可列舉物件。在這個過程中,與計算機科學概念如 閉包 (closures)、自由變數 (free variables)一級函數 (first-class functions) 進行互動。輕鬆識別閉包。找出可以有效使用 blocks 的模式,並使用它們重新實現常見的標準庫方法。追蹤 Symbol#to_proc 的運作方式,了解調用 procs 的不同方法。這本簡明的指南通過引人入勝的範例帶你了解不同類型的 Ruby 閉包,每一章都附有測試和挑戰你理解的練習。

當你完成這本書時,blocks、procs 和 lambdas 將成為你 Ruby 工具箱中不可或缺的一部分。

你需要的: Ruby 2.x 和對 Ruby 的基本熟悉。