Observer Pattern in Ruby
In this tutorial, we will examine the Observer pattern in Ruby.
The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
It's often…
Advanced Tutorials
Interpreter Pattern in Ruby
Implementing the Interpreter pattern in Ruby is pretty straightforward. Let's take a look at a simple example.
In this example, we have a simple DSL for creating a list of todos.
class Todo
def initialize(description)
@description = description
end
def to_s
"#{description}"
end
…
Factory Pattern in Ruby
This tutorial will show how to integrate the Factory Pattern in Ruby.
Factory Pattern is the creational design pattern in Ruby that defines an interface for creating objects and lets the classes that implement the interface decide which classes to instantiate.
Factory Pattern is also known as Virtual Constructor.
The Factory Pattern is helpful in…
Composite Pattern in Ruby
Let's explore the Composite Pattern in Ruby:
A composite is a structural design pattern that allows you to compose objects into a tree-like structure and then work with this structure as if it was a single object.
The composite pattern is often used in UI applications to represent objects in a tree-like structure (for…
Command Pattern in Ruby
This article will show how to implement the Command Pattern in ruby.
The command pattern is a behavioral design pattern that encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
Creating the Command Pattern in Ruby
We first need to create…
Builder Pattern in Ruby
In the next tutorial, we are going to teach you everything about how to implement the Builder Pattern in Ruby.
The builder pattern is excellent for creating complex objects and can be helpful in Ruby.
It's not always the best choice, and you should consider other options like the Factory Method or Prototype patterns.
But…
Adapter Pattern in Ruby
In this tutorial we are going to learn how to implement the adapter pattern in Ruby.
The adapter pattern is a way to adapters that act as translators between two incompatible interfaces.
You can use it to make unrelated classes work together. This is useful when you want to integrate 3rd party code or…
Emails in Rails
If you want to send emails in Rails, you can use the Mailer class.
The Mailer class is a wrapper around the Action Mailer gem.
Here's a simple example:
class UserMailer < ApplicationMailer
def welcome_email(user)
@user = user
mail(to: @user.email, subject: 'Welcome to My Awesome Site')
end
end
You can…
Redis in Rails
Let's check how to implement Redis in Rails. Redis is a fast, open-source, key-value database. It's perfect for storing things like session data, cached database queries, and other bits of information that need to be accessed quickly.
There are a few different Ruby libraries that you can use to connect to a Redis server.…
WebSockets in Rails
In this tutorial we will learn how to implement WebSockets in Rails. WebSocket is a communication protocol that makes it possible to create real-time applications.
The WebSocket protocol was designed to work on top of the existing HTTP protocol, and it enables full-duplex (two-way) communication between a client and a server.
The…