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: 63
Created: 2022-02-03
License: CC BY
Author(s): Jay McGavren
Using Blocks in Ruby

Others Ruby Tutorials

Ruby programming tutorial

Learn Ruby on Rails, PDF Tutorial

Ruby On Rails Programming Tutorial

Essential Ruby

RubyFu

Others related eBooks about Using Blocks in Ruby

Getting started with Java Language

This PDF document is a complet tutorial about Java programming language, free training course in 983 pages intended to beginner Java developer....

Think Java: How to Think Like a Computer Scientist

If you want to understand computer science, but have no programming experience, this book is for you. Think Java starts with the most basic programming concepts and carefully defines every term when it's first used. The authors then develop each new concept in a logical progression. Larger pieces ...

Restful Web Services

You've built web sites that can be used by humans. But can you also build web sites that are usable by machines? That's where the future lies, and that's what RESTful Web Services shows you how to do. The World Wide Web is the most popular distributed application in history, and Web services and mas...

Learning to Program Using Python

An introduction to computer programming, using the easy, yet powerful, Python programming language. Python, a cross-platform language used by such organizations as Google and NASA, lets you work quickly and efficiently, allowing you to concentrate on your work rather than the language. ...

JavaScript Bible

Download free course JavaScript Bible, pdf file on 2327 pages by Danny Goodman....

Annotated Algorithms in Python: with Applications in Physics, Biology, and Finance

This book is assembled from lectures given by the author over a period of 10 years at the School of Computing of DePaul University. The lectures cover multiple classes, including Analysis and Design of Algorithms, Scientific Computing, Monte Carlo Simulations, and Parallel Algorithms. These lectur...

COBOL Programming

Download COBOL tutorial in PDF,a free training courses under 236 pages to learn the basics of COBOL language...

Python for Everybody

Download free course Python for Everybody, pdf file on 247 pages by Dr. Charles Severance....

The Pascal Programming Language

This tutorial will give you great understanding on Pascal Programming concepts, Download free PDF training course on 13 pages by B.A.C. Schopman....

Essential Android

This book written to provide clear and concise explanation of topics for programmers both starting to learn the Android programming as well as those diving in more complex topics. Most examples are linked to online playground that allows you to change the code and re-run it....