Named Captures in Ruby Regular Expressions

In Ruby we can use the match method which belongs to the String class to both check a string for a regular expression match but also to extract data using captures. Captures allow you to extract part of the string... to isolate it. You do this by including () parentheses, with whatever that is i...

In Ruby On Rails By Leigh Halliday September 01, 2016

Leigh Halliday

Building a CLI in Ruby with GLI

Typically in Rails apps we use rake tasks as a way to interact with our application through the command line. We're all familiar with running code like rake db:migrate, or custom rake tasks that we create ourselves. There is another way to create CLI programs in Ruby with a very nice interface, ...

In Ruby On Rails By Leigh Halliday January 28, 2016

Leigh Halliday

Skinny controllers through refactoring

Controllers can get out of control. Their job should generally be quite simple. In an MVC framework such as Rails, they should have the job of knowing how to work with the Model in order to get what is needed for the View. In other words, they receive the user input (through params) and determine...

In Ruby On Rails By Leigh Halliday January 19, 2016

Leigh Halliday

Ruby web frameworks which aren't Rails: Cuba, Sinatra, Padrino and Lotus

It’s common for a Ruby developer to describe themselves as a Rails developer. It’s also common for someone’s entire Ruby experience to be through Rails. Rails began in 2003 by David Heinemeier Hansson, quickly becoming the most popular web framework and also serving as an introduction to Ruby for...

In Ruby On Rails By Leigh Halliday December 15, 2015

Leigh Halliday

Jbuilder to AMS - A tested journey

Not everyone is creating a new Rails app from scratch. Most of us have existing ones which may use RABL, Jbuilder, or a number of other options to generate JSON responses. When we're refactoring large and important parts of our app, how can we test to ensure that refactoring doesn't change the ap...

In Ruby On Rails By Leigh Halliday November 30, 2015

Leigh Halliday

Is it nil?

What is actually happening under the covers in Ruby when you ask if a variable is nil? It turns out that it's way simpler than you may think, and it all comes down to object oriented programming and inheritance. You've probably heard it said that everything in Ruby is an object... this includes ...

In Ruby On Rails By Leigh Halliday November 25, 2015

Leigh Halliday

Understanding method missing

In this article we look at how method_missing and respond_to_missing? work by looking at the StringInquirer class of Ruby on Rails.

In Ruby On Rails By Leigh Halliday September 08, 2015

Leigh Halliday

Exploring some string methods

It's important to be able to manipulate strings effectively in Ruby. Here are some details about some code I wrote to convert phone numbers that arrive in all different formats to a standard "555-555-5555" format that an API I'm working with expects.

In Ruby On Rails By Leigh Halliday August 20, 2015

Leigh Halliday

A Stack in Ruby using Linked Lists

A Stack is an abstract data type in programming which has a variety of uses. The basic premise of a Stack is that you can add a new value to the end (pushing), and you can remove the last value off of the end. This is referred to as LIFO - Last In First Out. Today we'll explore how to create a Stack in Ruby using Linked Lists.

In Ruby On Rails By Leigh Halliday July 03, 2015

Leigh Halliday

Weighted Quick Union & Quick Find Algorithm in Ruby

We are going to explore a Ruby implementation of the Weighted Quick Union & Quick Find algorithm. This is an algorithm used to find if there is a connection between two nodes. First we explore the simplest solution and then make it more performant.

In Ruby On Rails By Leigh Halliday June 29, 2015

Leigh Halliday

Avoid race conditions in Rails with Postgres locks

Earlier this year a programmer reported that he discovered a race condition bug in the Starbucks system which allowed him to essentially have an unlimited giftcard balance. It's obviously a problem that can have some serious financial implications. In this article we explore how to handle race conditions in Rails.

In Ruby On Rails By Leigh Halliday June 16, 2015

Leigh Halliday

Recursion in Ruby

Recursion in computer science is a method where the solution to a problem depends on solutions to smaller instances of the same problem (as opposed to iteration). Let's take a look at how recursion is done in Ruby and how it compares to iterative solutions.

In Ruby On Rails By Leigh Halliday May 26, 2015

Leigh Halliday

My solution to #5 Software Engineer challenge

I've been programming professionally for over 10 years, and I think it's ridiculous to expect or assume that everyone should be able to do specific kinds of "trick" problems that most likely will never come up except under very specific conditions in the workplace, depending where you work. That being said, I wanted to give it a try... it never hurts to practice and get some experience working on a new problem.

In Ruby On Rails By Leigh Halliday May 11, 2015

Leigh Halliday

Object hierarchy in Ruby

As a way to better understand how Ruby works, I started to dive into how object hierarchies work in the language. We're going to be covering the default ancestry chain in Ruby, how to create your own ancestors, and what the base level objects in Ruby actually do.

In Ruby On Rails By Leigh Halliday May 06, 2015

Leigh Halliday

Requiring Uniqueness in Rails

It's often the case that you want to ensure that you've got uniqueness in your data. You only want an email address to be used once... otherwise what would happen when that person tries to log in? Which user account would you log in with? Rails has an easy way to handle this, but the problem is that it isn't enough.

In Ruby On Rails By Leigh Halliday April 30, 2015

Leigh Halliday

Where is this method defined?

Today I was trying to write a test for a method, and I was expecting certain behaviour that I definitely wasn't getting. Why was this method returning me a valid value when it surely should be failing? Ruby provides a very useful object that allows you to dig into the details about your methods. You can find out where the method is defined, who owns it, and how many parameters it receives, among other things.

In Ruby On Rails By Leigh Halliday April 23, 2015

Leigh Halliday

Savon - SOAP that doesn't leave you feeling dirty

Depending on your field, and perhaps your age, you may not have ever worked with SOAP before. Most APIs these days communicate via RESTful JSON APIs. You're most likely familiar with these if you work with Angular or Ember, or if you've connected to the API of a modern website (Twitter, Shopify, even the New York Times). SOAP APIs work in XML, both the request and the response. Unlike most JSON APIs where you work with HTTP verbs (get, post, put, delete) with query or post variables, the entire SOAP request is in the body, in a big hunk of XML.

In Ruby On Rails By Leigh Halliday April 17, 2015

Leigh Halliday

Ruby Metaprogramming - Method Missing

Method missing is a method that ruby gives you access inside of your objects a way to handle situations when you call a method that doesn't exist. It's sort of like a Begin/Rescue, but for method calls. It gives you one last chance to deal with that method call before an exception is raised. Here we will explore how it works and provide some examples of different ways to use method_missing.

In Ruby On Rails By Leigh Halliday April 08, 2015

Leigh Halliday

Ruby Metaprogramming - Creating Methods

In this post I'll be discussing another aspect of metaprogramming in Ruby. The ability to create methods dynamically, during runtime. There are many reasons to do this, but one of them is to allow you to write generator methods to help you avoid writing repetitive code.

In Ruby On Rails By Leigh Halliday April 02, 2015

Leigh Halliday

Ruby Introspection - Metaprogramming

Introspection in general terms means to look inward. Humans can perform introspection, maybe questioning why we made a certain decision or finding out what makes us happy, and Ruby too can perform introspection.

In Ruby On Rails By Leigh Halliday March 21, 2015

Leigh Halliday

Creating a Ruby DSL

DSLs (Domain-specific language) are used heavily in Rails, but have you ever attempted to understand the concepts of them and tried creating your own? In this article I explore Blocks, DSLs and touch on a bit of meta-programming too!

In Ruby On Rails By Leigh Halliday March 14, 2015

Leigh Halliday

The simple but powerful Ruby Struct

A Struct in Ruby is one of the built-in classes which basically acts a little like a normal custom user-created class, but provides some nice default functionality and shortcuts when you don't need a full-fledged class.

In Ruby On Rails By Leigh Halliday February 26, 2015

Leigh Halliday

Why doesn't my code work outside of Rails?

Have you ever dealt with a NoMethodError exception for code that worked fine in Rails? There is a good chance that is because you were depending on some methods that Rails monkey-patched into core Ruby classes. This article provides an overview on monkey-patching, what Rails has monkey-patched, and some tips and suggestions.

In Ruby On Rails By Leigh Halliday February 20, 2015

Leigh Halliday

What is Rack?

Whether you're in the market for creating your own Ruby framework or whether you just want to gain a deeper understanding of how Rails works, it's a good thing to know Rack. Rack provides a minimal but standard interface for webservers to communicate with frameworks built in Ruby.

In Ruby On Rails By Leigh Halliday February 14, 2015

Leigh Halliday

Tree Structures in your Rails models

Tree structures are incredibly useful for creating vertical hierarchies in your data. They are for when you need to store categories, org structures, family trees, etc. Did you know there are many different ways to implement tree structures in Rails? Each has benefits and drawbacks, and in this article we'll explore the differences between them. The 3 patterns we'll investigate are: Parent-child, materialized path, and nested set.

In Ruby On Rails By Leigh Halliday February 07, 2015

Leigh Halliday

When your Rails app slows to a crawl

Hi, Leigh, are you busy? The website is no longer responding... can you investigate? A phone call nobody really likes to receive on a Saturday. No need to fear, after about an hour and a half of work the site was back up. Let's investigate some common issues that slow Rails applications down and how to solve them.

In Ruby On Rails By Leigh Halliday February 01, 2015

Leigh Halliday

Implementing Ruby's Collect Method

Collect allows you to transform each element of your collection object (Array, Hash, or your own object) into something else, ending up with an Array. I wanted to create my own collect method to see how it is implemented.

In Ruby On Rails By Leigh Halliday January 26, 2015

Leigh Halliday

Implementing Ruby's Tap Method

Ruby's tap method can be extremely useful, and was recently listed as one of the top five Ruby methods that you should be using on an Engine Yard blog. I wanted to see if I could implement my own version of the method to get a better understanding of how it works.

In Ruby On Rails By Leigh Halliday January 24, 2015

Leigh Halliday

Working with Enumerables: Four powerful collection methods

Mastering the Enumerable module can help you improve your Ruby skills drastically. It's a very powerful module and something you'll end up using more and more as you get comfortable with it. Here are 4 methods you can run on collections to help you transform and filter them.

In Ruby On Rails By Leigh Halliday January 22, 2015

Leigh Halliday

Adding translations to your Rails website

In this article I will explore the steps and code necessary to add I18n (internationalization: localization and translation) to this website. Topics included involve routing, static content, and dynamic content.

In Ruby On Rails By Leigh Halliday January 17, 2015

Leigh Halliday

Frontend (React, Javascript)

category-image

Software Development

category-image

Databases

category-image

Elixir

category-image