Ruby: Block basics

A Block in Ruby is equivalent to a Lambda or Anonymous (un-named) Function in other languages. It starts with do, ends with end, and its parameters are defined between |…

Ruby: Array basics

Mixed Types In Ruby, you don't have to make all of the elements of an Array be the same type: mixed_array = [1, "two", 3.0, joe] Indices Arrays are 0-indexed,…

Ruby: Ranges

Using 2 dots (1..5) in the Range means 1 - 5 inclusive (1, 2, 3, 4, 5) Using 3 dots (1...5) in the Range is exclusive; i.e. it excludes the…

Ruby: Comparisons, ==, ===

=== is the case-equal operator Comparing numbers pry> items = 1 pry> items === 1 => true pry> items === 2 => false Comparing ranges A range is case-equal with…

Ruby: Constants

LIMIT = 100 Even though LIMIT is a constant, Ruby will still allow you to change its value. It just gives you a warning when you do it, not an…

Ruby: Case (aka Switch) Statements

Case Statements Switch statements are formed using the case keyword in Ruby. Consider the following if - elsif - if statement: # statement-1 if item_counts[item_id] === 1 count = 1…