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
Pages : 25
Size : 2.0 MB
File type : PDF
Downloads: 81
Created: 2022-02-03
License: CC BY
Author(s): Jay McGavren
Using Blocks in Ruby

Warning: Trying to access array offset on false in /home/tutovnfz/public_html/article.php on line 233

Others Ruby Tutorials

Ruby On Rails Programming Tutorial

Ruby Kung Fu (RubyFu) Tutorial

Essential Ruby On Rails

Ruby Regexp

Ruby on Rails PDF Tutorial

Others related eBooks about Using Blocks in Ruby

Understanding Machine Learning

Download free course Understanding Machine Learning, pdf file on 449 pages by Shai Shalev-Shwartz, Shai Ben-David....

Python Notes for Professionals

This book goes beyond the basics to teach beginner- and intermediate-level Python programmers the little-known tools and constructs that build concise, maintainable code. Design better architecture and write easy-to-understand code using highly adoptable techniques that result in more robust and eff...

I Love Ruby

Ruby is an easy to learn programming language, it was invented by a guy named Matz in Japa..., download free Ruby tutorial in PDF (314 pages) created by Karthikeyan A K ....

Java Succinctly Part 1

Download free course Java Succinctly Part 1, pdf file on 125 pages by Christopher Rose....

Application Security in .NET Succinctly

Download free course Application Security in .NET Succinctly, pdf file on 103 pages by by Stan Drapkin....

Graph Algorithms

Download free course Graph Algorithms, pdf file on 257 pages by Mark Needham, Amy Hodler....

Spring Framework Tutorial

Download free Spring tutorial course in PDF, training file in 18 chapters and 68 pages. Free unaffiliated ebook created from Stack OverFlow contributor....

Full Speed Python

Download free course Full Speed Python, pdf file on 39 pages by João Ventura....

Visual Basic .NET Notes for Professionals

Download free course Visual Basic .NET Notes for Professionals, pdf file on 148 pages by Stack Overflow Community....

Learning Java

Java is a class-based, object-oriented programming language that is designed to have as fe..., download free Java tutorial in PDF (1225 pages) created by ....