Variable Assignment and Variable References in Ruby:
In ruby our assignment operator = allows us to point variables at objects.
Let us jump into some code and explore this further.

Below we will assign two variables to a single string object and see how this works.

acknowledgement = "Hello"acknowledgement.object_id #=> 100------------------------------------------salutations = acknowledgementsalutations.object_id #=> 100 

Here we have two different variables pointing at (also called referencing) one single object.

First we assign acknowledgement to the String object “Hello”.

Then we assign salutations to point at the String object that acknowledgement points to.

In the above image, “Referencing” and “Points at” are two terms for the same thing. When we assign an object to our variable, we are creating a pointer from our variable to our object.

Variable Reassignment, Mutation, and…

Here we will cover the differences and use cases for Array#each, Array#map, and Array#select.

What is the difference?

Array#each is used for iteration. #each is preferred by Rubyists in place of using a for loop. When a block is passed as an argument, each invokes the block once for each element of the array and returns the original array that it was invoked on.

Array#each does not consider the return value of the block.
If no block is passed, it returns an enumerator. It does not mutate the caller (the original array is left unmodified).

Array#map is used for transformation. When a block is…

The following article will attempt to thoroughly and precisely explain how the following code snippets work:

["Aa", "AAA", "b", "aa", "Aaa"].sort[100, 77, 200, 7, 21].sort

When sorting Strings, Array#sort uses the return value of the combined comparison operator (also known as the spaceship operator) String#<=> and the ASCII (hexadecimal) value of the character being sorted.

When sorting Integers, Array#sort uses the return value of the combined comparison operator Integer#<=> and compares each integer to each-other sorting them in ascending order based on the integer’s value.

ASCII Value Table:

Above we are looking at the red Char column, and the Dec (hexadecimal value)…

Methods that call a block repeatedly are called iterator methods.

Iterating through Arrays with #each

#each when used on an array passes a single parameter to the block.

Suppose we have an array of days of the week, and we want to loop through, capitalize and output each day of the week.

week = [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]

In other languages you might use a conventional for or while loop to step through each element of the array performing your given action, but with ruby you get a lot of built in iterator methods for collections.

Our ruby code might look…

Starting from the basics:

A single line block:

{ p "example string" } 

Multi-line block:

p "example string"

A block cannot be run directly, instead the block needs to be associated with or attached to a method call:

# Single line example:
2.times(method_param) { puts "example string" }
# Outputs:
#=> "example string"
#=> "example string"
# Multiple line example:
2.times(method_param) do
puts "example string"
# Outputs:
#=> "example string"
#=> "example string"

Adding Ruby Block Parameters:
You might have asked why I bothered showing the method parameters above as (method_param), In this case I wanted to show…

Markdown is lightweight markup language that is used in plaintext documents to add forming elements.

Writing in markdown is slightly different than using a WYSIWYG editor. Markdown doesn’t immediately show the changes to the document as you press buttons like “Bold”, instead with markdown you annotate the formatting you wish to show in line. This means if I wanted to create a heading I would do the following:

# This is now a H1 heading## This is now a H2 heading 

I recommend practicing with this free online program:

By using the below syntax rules, you can markup…

How local variables interact with method invocations, blocks, and method definitions.

What types of variables does Ruby have?

For the purpose of this article, a variable is just a label. It gives you, the programmer, the ability to name an object in your code.

Ruby has several types of variables, all defined by where they are accessible within your code.

  • Global Variables: “$global” ← (How the variable is declared.)
$variable = “I am available throughout your entire app”
  • Class Variables: “@@class” ← (How the variable is declared.)
@@class_variable = “I am accessible by instances of your class, as well as the class itself.”
  • Instance Variables: “@instance”← (How…

Combining the Two Layer Approach and PEDAC Framework to Solve Programming Problems

Launch School, where I attend Software Engineering School, talks extensively about when you start out as a programmer that there are two layers to every problem:

Layer 1.) The logic layerLayer 2.) The language syntax layer

The Logic Layer:
In the logic layer you have to figure out what the steps are for working through a problem. Unless you are working on a very simple problem, this logic layer is often unverifiable until you get to the syntax layer. …

Josiah Fordahl

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store