Flow of Execution

Learn about the flow in which Ruby runs our code.

We'll cover the following

Feel free to skip this chapter if you understand Ruby’s program flow, defining and calling a method, returning from it, perhaps calling another method, and so on. We’ve discussed this before. Because this is a potentially confusing topic, we’ll go over it again.

Note: It’s easy for programmers to forget to explain to beginners how Ruby flows through a program and in what exact order. This is called the flow of execution, or control flow.

When we execute a Ruby file (with the ruby runtime), it reads the Ruby code and executes it line by line, from top to bottom.

Example

Let’s look at our example from before, and how the Ruby control flow goes through it, in greater depth.

We’ve added parentheses for the method call to puts to make this more obvious, even though we recommend against this in practice:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy