Computer Science Basics

Blocks, Procs, and Lambdas in Ruby

Blocks, Procs, and Lambdas are Ruby’s approach to closures.

Blocks are any anonymous function that can be passed into methods. The’re the sections of code encapsulated between either braces `{}` or `do…end` syntax. In short: you’ve probably used them a lot before. Procs and Lambdas are both blocks that can be assigned to a variable.

Presenters and Decorators in Ruby on Rails

In presenters, you can access view helpers (eg: see the “h.link_to”) above in a way you can’t should you put this logic in the model. Ultimately, they allow you to separate out complex view logic from templates, while still having access to Rails’ view helpers.

Presenters are the view-focusing implementation of decorators, which serve the broader purpose of providing extra functionality to a specific instance of a class when (and only when) the decorator is instantiated.

What Is Scope?

In programming, scope is the area where variables, functions, and other name bindings can be used. In almost all languages, a variable can be accessed by any function/class inside the function/class its currently in, but not outside/above it