Home » Ruby » Page 7

Ruby

Testing with HTTP Requests

A slow and unreliable test suite is a test suite developers won’t want to work on. In Part One of this series, I dove deeper into how you might organize classes and methods for dealing with HTTP calls. In this article, we’re going to dig into how to write tests that use data returned from external HTTP APIs. We’ll also ...

Read More »

HTTP Calls in Ruby

An API doesn’t exist on its own. There are always two parties involved: The Client and the Server. In Rails, our apps are often the ones acting as the server, and we typically know how to troubleshoot the issues that inevitably arise. We can tail the logs to see what the incoming request looks like (the path, headers, params), how ...

Read More »

Good Module, Bad Module

You already know how to use modules in Ruby, but are you abusing them? In this post, we’ll take a look at different ways to program with modules and why they may or may not be a great idea. Namespace Modules give you an easy way to namespace the rest of your code. For example, when you generate a new ...

Read More »

Managing Private Dependencies with Bundler

Bundler is a great resource for managing dependencies in your Ruby projects. It helps verify compatible versions between each of your gem dependencies as well as create a version lock file. This guarantees that everyone who uses that same project will be working with the same gem versions that worked for you. Specifying Dependencies with Gemfiles The Gemfile is a ...

Read More »

Level Up Your Security in Rails

I am not a security expert, and the truth is that most other developers aren’t either. I haven’t created my own hashing or encryption algorithm, I don’t know the inner workings of TLS, nor the different ciphers that are available, but that doesn’t give me a free pass when it comes to protecting my users and their data. One amazing ...

Read More »

The Pros and Cons of Ruby Refinements

In Ruby 2.0.0, refinements were introduced as a new feature. Monkey patching has been used for a long time for modifying code behavior, but it creates side effects in code elsewhere that ends up affected by the modified code. The purpose of Ruby refinements is to provide a solution by scoping changed behavior to the very specific area of code ...

Read More »

Why You Shouldn’t Roll Your Own Authentication

“Should I roll my own authentication?” Given how easy it is to build an authentication system with Rails’ has_secure_password and the authenticate method (as shown in Hartl’s tutorial), why would you jump straight to a gem like Devise, which is hard to understand and customize? In this article, I hope to lay down the case for why I think the ...

Read More »

Parsing Binary Data Formats

This story started with me wanting to write a steganography tool. Steganography is the process of hiding information inside a file, typically an image. To do that, I had to write an image decoder first because you can’t just start changing random bytes. All that will do is make the image invalid or corrupt. I selected PNG as the image ...

Read More »

Metaprogramming in Ruby

In this article, we’ll be looking at a few different aspects of metaprogramming in Ruby. For starters, what is metaprogramming? Metaprogramming is the writing of computer programs with the ability to treat programs as their data. It means that a program could be designed to read, generate, analyze, or transform other programs and even modify itself while running. We’ll specifically ...

Read More »