Ruby Post Index

How to Use The Ruby Alias Keyword

You can give an alternative name to a Ruby method in two ways: alias (keyword) alias_method Because they do the ...
Read More

9 New Features in Ruby 2.6

A new version of Ruby is coming with new features & performance improvements. Would you like to keep up with ...
Read More

Ruby Templating Engines: ERB, HAML & Slim

ERB is a templating engine. A templating engine allows you to mix HTML & Ruby. This helps you generate your ...
Read More

How to Use attr_accessor, attr_writer & attr_reader

Let's say that you have a class with instance variables & you want to expose them to the outside world ...
Read More

Ruby Coding Challenges & How to Solve Them

Doing coding challenges is an excellent way to improve your Ruby & problem-solving skills. Why? Because you put all your ...
Read More

How to Check If a Variable is Defined in Ruby

Ruby has this defined? keyword that helps you check if a variable is defined or not. If the variable exists ...
Read More

Understanding The Differences Between Puts, Print & P

There are many ways to print something in Ruby. Here are the most useful: puts print p But how are ...
Read More

How to Use RSpec Mocks (Step-By-Step Tutorial)

What is a mock in RSpec? (Or a mock in general, because this isn't a concept unique to RSpec.) A ...
Read More

How to Read & Parse CSV Files With Ruby

CSV stands for "Comma-Separated Values". It's a common format for exporting & importing data. For example: You can export your ...
Read More

How to Use Ruby Any, All, None & One

Today you'll learn about 4 Enumerable methods that will help you check a conditional statement against an array of elements, ...
Read More

How to Use the Ruby Grep Method (With Examples)

Let's talk about the grep method. What can this method do for you? You can use Grep to filter enumerable ...
Read More

What is Ruby on Rails?

Ruby on Rails is an open-source web application framework. A framework is a collection of code, tools & utilities that ...
Read More

How to Use The Ruby Map Method (With Examples)

Map is a Ruby method that you can use with Arrays, Hashes & Ranges. The main use for map is ...
Read More

Understanding Method Visibility In Ruby

What does public, private & protected mean in Ruby? These 3 methods control the public interface of your class. They ...
Read More

How To Delegate Methods in Ruby

In Object-Oriented Programming, there are two ways for classes to work together. They are: Inheritance Composition With inheritance, you create ...
Read More

The Ultimate Guide to Ruby Gems, Gemfiles & Bundler

A Ruby gem packages together Ruby code in a way that is easy to share with others. Gems solve mostly ...
Read More

How to Use Ruby Conversion Methods

You would like to use string methods (like gsub) but you're working with an integer... What can you do? Use ...
Read More

How to Use The Ruby Super Keyword

What does the super keyword do in Ruby? It calls a method on the parent class with the same name ...
Read More

Rack Explained For Ruby Developers

Would you like to know what goes on behind the scenes of Rails, Sinatra, and other Ruby web frameworks? Then ...
Read More

Solving the N-Queens Problem With Ruby

N-Queens is an interesting coding challenge where you have to place N queens on a N * N board. It ...
Read More

How to Use The Ruby Set Class

What is a Ruby set? A set is a class that stores items like an array... But with some special ...
Read More

The Ultimate Guide to HTTP Requests in Ruby

If you'd like to get information from a website, or if you'd like to submit forms, upload files... ...you'll need ...
Read More

The Definitive RSpec Tutorial With Examples

Would you like to learn how to write tests for your Ruby applications using RSpec? Then you're in the right ...
Read More

Everything You Need to Know About Ruby Operators

Ruby has a lot of interesting operators, like the spaceship operator (<=>), the modulo assignment operator (%=), and of course ...
Read More

Ruby’s Powerful Method Arguments & How To Use Them Correctly

I got an email asking for my opinion about when to use keyword arguments. I thought I'd expand my answer ...
Read More

Why Do We Create Classes?

Following my last article, why do we use nil, I thought it'd be a good idea to ask this question ...
Read More

Why Do We Use Nil?

I was having a chat with a friend about a piece of Ruby code & the topic of return values ...
Read More

How To Use The Singleton Pattern In Ruby (And Why You Should Avoid It)

Have you ever wanted to create a class that can only have one instance? Yes? No? Maybe? Well... That's exactly ...
Read More

How To Dramatically Improve Your Ruby Code With Fundamental OOP Principles

A very important topic in object-oriented design is cohesion & coupling. Cohesion is about the relationship between all the methods ...
Read More

How to Use The Strategy Design Pattern in Ruby

Let's talk about the strategy design pattern! This design pattern helps you change the main algorithm inside a method. You ...
Read More

How To Use The Decorator Pattern in Ruby

The decorator design pattern... What is it, and how can you use this pattern in your Ruby projects? The decorator ...
Read More

How To Create A Memory Leak in Ruby

There are a few articles out there about how to find memory leaks. But how about creating one? I think ...
Read More

Profiling Ruby’s Memory Allocation with TCmalloc

Everytime Ruby needs to request memory from the operating system it has to call the malloc function. This function is ...
Read More

The Definitive Guide To Time Complexity For Ruby Developers

Time complexity is one of the most interesting concepts you can learn from computer science, and you don't need a ...
Read More

How to Write a Ruby C Extension

Writing a C extension allows you to interact with Ruby from C. You may want to this if there is ...
Read More

What Are Ruby Symbols & How Do They Work?

A symbol looks like this: :testing Some people confuse symbols with variables, but they have nothing to do with variables ...
Read More

Functional Programming In Ruby

Maybe you just heard about functional programming & have some questions. Like... What is functional programming exactly? How does it ...
Read More

Ruby String Methods (Ultimate Guide)

A string is a sequence of characters. Strings are objects so they have a lot of methods you can use ...
Read More

Everything You Need to Know About Nil

Nil... What is it, really? Well, nil is just a Ruby object. As you can see here: nil.class # NilClass ...
Read More

Ruby Is Hiding Errors From You!

Ruby will intentionally hide some exceptions from you. Sometimes this can be useful. Like when using the Kernel#loop method with ...
Read More

Learn to Implement & Use Prefix Trees in Ruby

A prefix tree (also known as a trie) is a data structure that helps you organize a word list & ...
Read More

Atom Tricks, Plugins & Shortcuts for Ruby Developers

If you are using Atom for Ruby development then you probably know that there are plugins (packages in Atom) that ...
Read More

Build Your Own Link Shortener App with Ruby & Sinatra

If you are looking for a little project to work on & practice your Ruby skills then you are in ...
Read More

Performance Improvements in Ruby 2.5

New Ruby versions keep improving & Ruby 2.5 is no different. Ruby 2.5 is introducing some optimizations: String interpolation will ...
Read More

Turn Rows Into Columns With The Transpose Method

Today you are going to learn how to deal with grids in Ruby using the Ruby transpose method. Imagine that ...
Read More

Array#zip Method

Let's say that you want to compare two arrays, element by element so you can find the differences. Or maybe ...
Read More

7 Little-Known Ruby Methods To Help You Write Better Code

Did you know that using the right Ruby method can save you a lot of work? The more methods you ...
Read More

Build an Image Downloader in Ruby

Build an Image Downloader in Ruby Watch this video to learn how to build an image dowloader program step-by-step using ...
Read More

Code Reading Adventures in The Land of Ruby

Awesome print is a nice gem that formats your output in irb & pry to make it more readable. For ...
Read More

A Quick Analysis of How Sinatra Works

Sinatra is a Ruby web framework. It's like Rails little brother... Let's explore how Sinatra works: What happens when you ...
Read More

Practical Linked List in Ruby

This is the 3rd entry in the "Practical Computer Science in Ruby" series! Today we are going to talk about ...
Read More

The Ultimate Guide to Ruby Sorting

How many ways are there to sort an array in Ruby? More than you think... ...even though Array only has ...
Read More

Everything You Need to Know About Ruby Constants

There is a lot more to Ruby constants that you might think... For example, you can change the value of ...
Read More

The Hidden Costs of Metaprogramming

Metaprogramming sounds like a very fancy word, but is it any good? It can be useful, but many people don't ...
Read More

There Is No Magic in Ruby

You may have heard (or even said yourself) that Rails / Ruby has too much magic... But where does that ...
Read More

Practical Graph Theory in Ruby

This is the next installment in the "Practical Computer Science" series, where you will learn how to apply classic computer ...
Read More

An Object That Behaves Like a File?

If you are looking for an object that behaves like an IO object (files, sockets, etc), but that you can ...
Read More

Stop Using Case Statements in Ruby

Are you using the full power of OOP (Object-Oriented Programming) or are you missing out? If you are taking decisions ...
Read More

Ruby Under The Hood: Memory Layout of an Object

If you enjoy seeing how things work under the hood I think you are going to love this post... ...because ...
Read More

Practical Computer Science in Ruby: Using Stacks to Solve Problems

If you don't have a CS (Computer Science) degree you might feel like you are missing out on something... Or ...
Read More

How to Make Your Classes More Powerful by Implementing Equality

How do you compare two things in Ruby? Using == as you already know... but did you know that == ...
Read More

15 Weird Things About Ruby That You Should Know

15 Weird Things About Ruby That You Should Know By Jesus Castello Ruby is an amazing language with a lot ...
Read More

Hash Tables Explained

One of my favorite data structures is the hash table because it's simple & powerful. You probably have used it ...
Read More

Packing & Unpacking: A Guide to Reading Binary Data in Ruby

Working with text is a lot easier than working with binary data... ...with text you can use regular expressions & ...
Read More

How To Spy on Your Ruby Methods

Ruby has a built-in tracing system which you can access using the TracePoint class. Some of the things you can ...
Read More

9 New Features in Ruby 2.4

It has become a tradition to release new Ruby versions on Christmas. And in this post I want to cover ...
Read More

How to Write a Port Scanner in Ruby

Why would you want to write a port scanner? Writing a port scanner is a great way to learn the ...
Read More

A Quick Analysis of How Minitest Works

As you may know, Minitest is the default testing library for Rails & DHH's favorite. Some people prefer it for ...
Read More

What’s Happening in Your Ruby Application?

What would you do if you wanted to know what's going on with your Ruby application? In Ruby we don't ...
Read More

Build Your Own Web Server With Ruby

Have you ever built your own web server? I think this is a great learning exercise & in this post ...
Read More

Behind The Scenes: How Numbers Work in Ruby

Ruby 2.4 will be merging both Fixnum & Bignum into the same class (Integer) so I think this is a ...
Read More

Writing a Shell in 25 Lines of Ruby Code

If you use Linux or Mac, every time you open a terminal you are using a shell application. A shell ...
Read More

Building Your Own Linux Tools with Ruby: A Practical Guide

Tools like ps, top & netstat are great, they give you a lot of information about what's going with your ...
Read More

Ruby Ranges: How Do They Work?

What is a Range in Ruby & how does it work? In this article you'll discover: How to create a ...
Read More

5 Useful Examples From The Ruby Standard Library

The Ruby Standard Library is a series of modules & classes that come with Ruby but are not part of ...
Read More

How to Generate Weighted Random Numbers

Random numbers usually follow what we call a 'uniform distribution', meaning that there is the same chance that any of ...
Read More

Metaprogramming in The Wild

You may have read about Ruby metaprogramming before & maybe you have used it in some of your projects... But ...
Read More

Learn to Use the Twitter API with Ruby

Do you want to learn how to write a Twitter application using Ruby? Then you are in the right place! ...
Read More

My New Favorite Enumerable Method

Enumerable is an amazing module, and it's a big part of what makes Ruby a great programming language. Ruby's Enumerable ...
Read More

Exploring MRI Source Code

If you have been using Ruby for a while you are probably curious about how some things work under the ...
Read More

The Ultimate Guide to Blocks, Procs & Lambdas

Ruby blocks, procs & lambdas. What are they? How do they work? How are they different from each other? You ...
Read More

11 Ruby Tricks You Haven’t Seen Before

Looking for some cool Ruby tricks? You found them! In this article I want to share with you some of ...
Read More

Understanding Mutable Objects & Frozen Strings

Let's talk about mutability. What does it mean for an object to be mutable? Don't let the fancy word deceive ...
Read More

Ruby Time & Date Classes

In this article you will learn what time-related classes & methods are available in Ruby and how to use them ...
Read More

Introduction to Refactoring

If you aren't familiar with the term, refactoring is the act of improving the quality of code without changing what ...
Read More

The Many Uses Of Ruby Case Statements

Whenever you need to use some if / elsif statements you could consider using a Ruby case statement instead. In ...
Read More

N-gram Analysis for Fun and Profit

What would you do if you are given a big collection of text & you want to extract some meaning ...
Read More

Recursion and Memoization in Ruby

Have you ever wondered if there is an alternative to iteration? Well I have good news for you: there is, ...
Read More

Static Analysis in Ruby

If you want to know something about your source code, like the name and line number of all your methods, ...
Read More

Debugging Your Ruby Programs

How often does your program do exactly what you want the first time around? Many times our programs dont't work ...
Read More

Using Ruby Threads

Using ruby threads you can make your applications do multiple things at the same time, making them faster. In MRI ...
Read More

Mastering Ruby Regular Expressions

Ruby regular expressions (ruby regex for short) help you find specific patterns inside strings, with the intent of extracting data ...
Read More

How to Use Ruby Struct & OpenStruct

A Ruby struct solves one simple problem: How can you create a class that is used for storing data & ...
Read More

The Definitive Guide to Writing & Reading Files in Ruby

In this article you'll learn how to: Read & write files with Ruby List the contents of directories Create temporary ...
Read More

The Definitive Guide To Ruby Arrays

What is a Ruby array? An array is a fundamental data structure that is used to store data in memory ...
Read More

Ruby Network Programming

Do you want to create custom network clients & servers in Ruby? Or just understand how that works? Then you ...
Read More

How to Build a Parser With Ruby

Parsing is the art of making sense of a bunch of strings and converting them into something we can understand ...
Read More

How to Write Your Own Caesar Cipher Encoder

Have you ever heard of the Caesar cipher? Julius Caesar used this technique to conceal secret messages from his enemies! ...
Read More

How to Generate Random Numbers & Strings in Ruby

You can generate Ruby random numbers & strings using what you'll learn in this post! With a random number you ...
Read More

Alphanumeric sorting

Time for a bit more sorting. Today our task is to sort an array of file names based on the ...
Read More

How to Parse HTML in Ruby

Are you trying to parse HTML with Ruby? This task can be a bit difficult if you don't have the ...
Read More

Ruby String Formatting

Let's talk about how you can format strings in ruby. Why would you want to format a string? Well, you ...
Read More