In Ruby, is an if/elsif/else statement's subordinate block the same as a 'block' that is passed as a parameter?

Viewed 575

I was doing some reading on if/elsif/else in Ruby, and I ran into some differences in terminology when describing how control expressions work.

In the Ruby Programming Wikibooks (emphasis added):

A conditional Branch takes the result of a test expression and executes a block of code depending whether the test expression is true or false.

and

An if expression, for example, not only determines whether a subordinate block of code will execute, but also results in a value itself.

Ruby-doc.org, however, does not mention blocks at all in the definitions:

The simplest if expression has two parts, a “test” expression and a “then” expression. If the “test” expression evaluates to a true then the “then” expression is evaluated.

Typically, when I have read about 'blocks' in Ruby, it has almost always been within the context of procs and lambdas. For example, rubylearning.com defines a block:

A Ruby block is a way of grouping statements, and may appear only in the source adjacent to a method call; the block is written starting on the same line as the method call's last parameter (or the closing parenthesis of the parameter list).

The questions:

  • When talking about blocks of code in Ruby, are we talking about the group of code that gets passed in to a method or are we simply talking about a group of code in general?
  • Is there a way to easily differentiate between the two (and is there a technical difference between the two)?

Context for these questions: I am wondering if referring to the code inside of conditionals as blocks will be confusing to to new Ruby programmers when they are later introduced to blocks, procs, and lambdas.

1 Answers
Related