Using Blocks in Ruby



Download free course Using Blocks in Ruby, pdf file on 25 pages by Jay McGavren.
Unannounced and unmarked, blocks turn up all over Ruby programs. Their use ranges from some of Ruby's most basic structures, such as loops, to some of its most sophisticated tricks. Similar to closures or lambdas in other languages, blocks enable some of Ruby's vaunted efficiency. Blocks even allow other people to write some of the code you use.

With this excerpt from Head First Ruby, you'll learn about blocks by looking at each concept from different angles. Exercises throughout will help you understand and remember how these closure-like structures work. In fact, these exercises are key component to our unique, hands-on Head First approach.
  • Bend your mind around blocks and methods
  • Build blocks into larger structures
  • Do heavy lifting easily with blocks
  • Get more done with less code

Table of contents

  • Blocks are mind-bending stuff. But stick with it!
  • Defining a method that takes blocks
  • Your first block
  • Flow of control between a method and block
  • Calling the same method with different blocks
  • Calling a block multiple times
  • Block parameters
  • Using the "yield" keyword
  • Block formats
  • The "each" method, step-by-step
  • DRYing up our code with "each" and blocks
  • Blocks and variable scope
  • Using "each" with the "refund" method
  • Using "each" with our last method
  • Our complete invoicing methods
  • We've gotten rid of the repetitive loop code!
  • Utilities and appliances, blocks and methods
Pages25
Size2.0 MB
File typePDF
Downloads159
Created2022-02-03
LicenseCC BY
Author(s) Jay McGavren
Cover of Using Blocks in Ruby

Download

  • Cobol programmer's guide

    Download a complet PDF tutorial about Cobol for programmers ,it shows you how to develop COBOL programs that use the database languages SQL and PL/SQL....

  • Statistics with Julia

    Ccurrently many of Julia's users are hard-core developers that contribute to the language'..., download free Julia tutorial in PDF (413 pages) created by Hayden Klok ....

  • Programming Languages and Systems

    Download free course Programming Languages and Systems, pdf file on 1056 pages by Amal Ahmed....

  • Language D tutorial in PDF

    Download free Language D tutorial course in PDF, training file in 17 chapters and 44 pages. Free unaffiliated ebook created from Stack OverFlow contributor....

  • A Byte of Python

    Download free course A Byte of Python, pdf file on 117 pages by Self-publishing....

  • Exploring Swift

    Swift is more than just a modern replacement for Objective-C. Ever since going open source..., download free Swift tutorial in PDF (94 pages) created by ....

  • Fortran 90 for Beginners

    Download free Fortran 90 Programming language course material, tutorial training, a PDF file by Tadziu Hoffmann & Joachim Puls....

  • Building Skills in Python: A Programmer's Introduction to Python

    This book is a complete presentation of the Python language. It is oriented toward learning, which involves accumulating many closely intertwined concepts. In our experience teaching, coaching and doing programming, there is an upper limit on the "clue absorption rate". In order to keep within thi...

  • Principles of Programming Languages

    Download free course Principles of Programming Languages, pdf file on 163 pages by Mike Grant, Zachary Palmer, Scott Smith....

  • Kotlin tutorial in PDF

    This Kotlin pdf tutorial will teach you how to develop with Kotlin on Android Studio as part of the mobile development for Android platforms....