Rubyland

news, opinion, tutorials, about ruby, aggregated
Sources About
Pat Shaughnessy 

Visiting an Abstract Syntax Tree


Joshua Tree National Park (via: Wikimedia Commons)

In my last post, I explored how Crystal parsed a simple program and produced a data structure called an abstract syntax tree (AST). But what does Crystal do with the AST? Why bother going to such lengths to create it?

After Crystal parses my code, it repeatedly steps through all the entries or nodes in the AST and builds up a description of the intended meaning and behavior of my code. This process is known as semantic analysis. Later, Crystal will use this description to convert my program into a machine language executable.

But what does this description contain? What does it really mean for a compiler to understand anything?…

Ruby Conferences 'n' Camps in 2022 - What's Upcoming? 

Punk's Not Dead Conf - Ruby (Pixel) Art Programming @ Vienna, Austria, Central Europe Announced

Conferences 'n' Camps

What's News? What's Upcoming in 2022?

Punk's Not Dead Conf - Ruby (Pixel) Art Programming
Jun/29+30 (2d) Wed+Thu @ Vienna, Austria, Central Europe

See all Conferences 'n' Camps in 2022».

Ruby Conferences 'n' Camps in 2022 - What's Upcoming? 

Sin City Ruby @ Las Vegas, Nevada, United States Announced

Conferences 'n' Camps

What's News? What's Upcoming in 2022?

Sin City Ruby $299 - $499
Mar/24+25 (2d) Thu+Fri @ Las Vegas, Nevada, United States

See all Conferences 'n' Camps in 2022».

Ruby Conferences 'n' Camps in 2022 - What's Upcoming? 

European Ruby Konference (EuRuKo) @ Helsinki, Finnland Announced

Conferences 'n' Camps

What's News? What's Upcoming in 2022?

European Ruby Konference (EuRuKo)
Oct/13+14 (2d) Thu+Fri @ Helsinki, Finnland • (Updates)

See all Conferences 'n' Camps in 2022».

Ruby on Rails 

Rails 7.0.1, Webpacker retirement and more

Hi, Wojtek here introducing you to this year changes in the Rails.

Released Rails 7.0.1
The Ruby 3.1 is fully supported with this release. It also contains few bug fixes and documentation improvements.

Retirement of Webpacker
Only security issues will be considered and there will be no version 6 release of Webpacker. There is a switching guide to jsbundling-rails ready.
Thank you to everyone who’ve contributed to Webpacker over the last five-plus years!

Autoloaded paths are no longer in load path
Starting from Rails 7.1, all paths managed by the autoloader will no longer be added to $LOAD_PATH.
This means it won’t be possible to load them with a manual require call, the class or module…

Added update_attributes! to…

Remote Ruby 

Autoscaling Rails with Adam McCrea

[00:01:10] Adam tells us a little bit about himself and how he got into this field. 


[00:03:48] We learn more about Adam’s career path from edge case to Rails Autoscale. 


[00:05:09] Adam gives us a rundown of what Rails Autoscale is and the problem it solves.


[00:06:41] Andrew wonders if Rails Autoscale will help if you don’t have enough memory, and Adam tells us the solution for this.


[00:09:39] Adam fills us in on the support load he gets and the kind of support he gives.


[00:10:39] Find out how Rails Autoscale is different compared to other autoscalers Adam tried.

 

[00:16:05] If you’re wondering when Rails Autoscale is right for you, Adam tells us. Also, he announces that he’s working…

Shopify Engineering - Shopify Engineering 

Cloud, Load, and Modular Code: What 2022 Looks Like for Shopify

Awesome Ruby Newsletter 

💎 Issue 296 - 🎉 Happy 10th Birthday, Sidekiq! 🎂

zverok with ruby 

Programming language evolution: with all that, we are still flying

Final part of adventures in understanding, explaining, and challenging the facts that should be obvious.
(Part 1Part 2Part 3)

This article is written for my Substack, you can subscribe to it by email now!

In the previous two parts, I described how working on Ruby’s changelog made me imagine I understand language’s logic and intentions behind it. Then, that fantasy brought me to participate more insistently in language development. And then, that participation made me suffer when several aspects of Ruby 2.7 evolution hasn’t developed the way I expected—and in one case, an important feature was reverted a couple of months before the final release.

I was devastated. Probably it…

Ruby Weekly 

WebAssembly support coming to CRuby

#​587 — January 20, 2022

Read on the Web

Ruby Weekly

Proposal to Merge WASI-Based WebAssembly Support into Ruby — There have been experiments before, but having WebAssembly as an officially supported target for Ruby would open up some interesting use cases. While this is exciting news, it’s very early days and with a variety of expected limitations (e.g. around threading). A story we’ll keep an eye on, for sure, and hopefully a headline feature for Ruby 3.2.

Yuta Saito et al.

🎉  Happy 10th Birthday to Sidekiq, the Background Job Processor — A true Ruby success story! The creator of the hugely popular Side…

Boring Rails: Skip the bullshit and ship fast |  

Accessing Rails environment variables from a StimulusJS Controller

Environment variables are a great way to configure your Rails apps. You can use the Rails.env variable to conditionally change behavior when you are in development/test or production. And you can add your own application specific variables for things like API tokens or global settings.

While Stimulus has a values API to read from HTML data attributes, sometimes you need data that you don’t want to pass in every time you create a controller.

One alternative is to use <meta> tags when rendering your view. Then, inside your Stimulus Javascript code, you can query the <meta> DOM element to retrieve the value.

Usage

First, add the <meta> tag to your application template inside the <head>

Saeloun Blog 

Deep dive into the new Suspense Server-side Rendering ( SSR ) architecture in React 18

The much anticipated React 18, (now in beta) is on the horizon and offers a new Suspense SSR Architecture.

To understand the new architecture, one must be familiar with the basic concepts like client-side rendering, server-side rendering, hydration, etc.

We have explained these concepts in our previous blog post related to Hydration. It is recommended to go through it before jumping to the new architecture.

How does SSR work?

In SSR, data is fetched, and the HTML is generated from the React components on the server. The HTML is then sent out to the client.

Here are the steps which are followed during SSR:

  1. Data is fetched for the entire application on the server
  2. The HTML is…
BootrAils 

Ruby, map with index

Intro

Just like many other programming languages, the Map method is also in ruby. You use a ruby map or map, in general, to transform the data and perform functions on each element of the object. You can use it with the hashes, ranges, and arrays. All these work as an Enumerable object with a map. Let's dive into this guide and learn more about the ruby map method.

Map with index

There is no direct "map_with_index" method in Ruby. Instead, you could do one of these :

my_array = [:mouse, :bat, :pangolin]
newly_created_array = my_array.each_with_index.map { |value, index| "The #{value} is at position #{index}" }
# => ["The mouse is at position 0", "The bat is at position 1", "The pangolin is…

In this example, my_array is left as-is.

Unsurprisingly, the each_with_index method returns a two-dimensional array

my_array = [:…
Test Double Blog 

Stop paying tech debts, start maintaining code

You keep using that word. I do not think it means what you think it means. - Inigo Montoya Tech debt is a term that’s tossed around a lot in software.
The Rails Tech Debt Blog 

On How We Use RuboCop and StandardRB

We all have been there, we work on a project and, over time, we write similar code in different ways (either by two different developers or by the same developer). We have two blocks of code that follow the same logic but look different; and we have to make an extra effort to understand them only because the code is written in a different way.

Defining a code style will prevent this, but we need a way to enforce it. In this article, we’ll show what’s our setup to use StandardRB (and RuboCop) to improve the quality of the code by keeping a consistent style to help the developers.

StandardRB

StandardRB is a gem built on top of RuboCop that defines a set of rules. It uses RuboCop under…

JRuby.org News 

JRuby 9.3.3.0 Released

The JRuby community is pleased to announce the release of JRuby 9.3.3.0

JRuby 9.3.x is compatible with Ruby 2.6.x and stays in sync with C Ruby. As always there is a mix of miscellaneous fixes so be sure to read the issue list below.

The big news this release is support for Apple’s M1 family of processors (Apple Silicon) via an update to our native FFI backend library. Nearly all our usual test suites are passing on M1 and we have added a self-hosted CI runner thanks to MacStadium’s OSS program. Callbacks from C to Ruby are unsupported, but this does not affect any libraries we ship. We will continue to…

RubyGems Blog 

Rubygems Adoptions

No matter how near and dear a project was once to your heart, we all know that with time priorities change. You may no longer have the time or enthusiasm toward solving the issues of strangers on the internet as you once used to. It is reasonable for you to expect that the members of the community who have benefited from your work all this time will step up and carry your legacy (pun intended) forward. After all, it is in everyone’s interest that a project used by the wider community doesn’t get stalled.

We are trying to introduce a formal process to deal with scenarios where owners may be interested in handing over the stewardship of a gem to new members or just need more helping hands. G…

Closer to Code 

Reduce your method calls by 99.9% by replacing Thread#pass with Queue#pop

When doing multi-threaded work in Ruby, there are a couple of ways to control the execution flow within a given thread. In this article, I will be looking at Thread#pass and Queue#pop and how understanding each of them can help you drastically optimize your applications.

Thread#pass - what it is and how does it work

One of the ways you can ask the scheduler to "do something else" is by using the Thread#pass method.

Where can you find it? Well, aside from Karafka, for example in one of the most recent additions to ActiveRecord called #load_async (pull request).

Let's see how it works and why it may or may not be what you are looking for when building multi-threaded applications.

Ruby docs

The Ruby on Rails Podcast 

Episode 401: From Frontend to Fullstack with Shameel Abdullah

Shameel Abdullah is a Senior Developer at Shopify. Starting his career with frontend development, he has transitioned to a fullstack developer, working with Rails across multiple startups. He, Nick and Brittany chat about GraphQL and frontend opinions.

Show Notes & Links:

Sponsored By:

Hook Relay

Hook Relay is a service that makes sending and receiving webhooks reliable, secure, and transparent—automatically. Sign up now, and you can start receiving webhooks from integrations like GitHub, etc., even before you have an app to receive them.

Scout APM

Try their…

Ruby Rogues 

Stimulus, Hotwire, and Turbo, Oh My! - RUBY 531

If you’re wondering how to make sense of all these frameworks, you’ve come to the right podcast. In this episode, the Rogues dive DEEP into the pros and cons of Stimulus, Hotwire, Turbo, React, Rails, and more; why certain communities are divided amongst each other (and how to fix it); and what tools you NEED to try in 2022.

In This Episode

This tendency in the Rails community that reveals why users are slow to try Hotwire
What Charles learned from comparing React vs. Stimulus at his old job (and how Rails came to the rescue)
Why those in the Java community are seeing React as a “blackhole that’s sucking up everything” (and why some of the Rogues disagree)
Up and coming…

Greater Than Code 

267: Handling Consulting Businesses and Client Loads

00:36 - Panelist Consulting Experience and Backgrounds

10:00 - Marketing, Charging, and Setting Prices

28:34 - GeePawHill Twitter Thread - Impact Consulting

38:43 - Management & Mentorship

52:15 - Explaining Value and Offerings

55:08 - Ideal Clients

Reflections:

Mae: The phrase “indie”.

Casey: Having a Patreon to help inspire…

Saeloun Blog 

Rails 7 renders accurate plain text output for nested fields

ActionText is a power-packed tool to easily build WYSIWYG editors for your Rails applications. It comes with an array of editor options and transformers. One of them is the Plain Text transformer which converts HTML input to plain text output.

Before

As with any editors, some wonkiness is expected! When using to_plain_text on an ActionText content containing nested lists, the output does not meet expectations. For example, when using indentations to indicate nested list levels, converting to plain text does not preserve the indentation.

ActionText::Content.new("<ul><li>Item 1<ul><li>Item a</li></ul></li></ul>").to_plain_text

=> "• Item 1• Item a"

However, the expected output is close…

Boring Rails: Skip the bullshit and ship fast |  

Rails validations: database level check constraints

One of the most common Rails tips is to back up your ActiveRecord model validations with database level constraints.

Because there are times when validations are skipped, it’s best to let your database be the last line of defense to maintain your data integrity. You can add a validates :name, presence: true line to your model, but if null values sneak into your database, your app will still throw an exception if you call name.downcase on nil.

The most common examples are pairing presence validations with non-null columns and unique validations with a unique database index.

But did you know you can go a step further using a database feature called “check constraints”.

Usage

Check…

Mike Coutermarsh 

How our Rails test suite runs in 1 minute on Buildkite

View this post on PlanetScale.

Ruby Together News 

December 2021 Monthly Update

Hello! Welcome to the monthly update. During December, our work was supported by Zendesk, Stitch Fix, DigitalOcean, and many others.

ruby together news

In December, Ruby Together was supported by 35 different companies, including Ruby member Zendesk. 2 companies joined as new members.

On top of those companies, 2 new developers signed up as members, including Kyoungwon Lee. In total, we were supported by 124 developer members. Thanks to all of our members for making everything that we do possible. <3

rubygems & bundler news

In December, we released new versions for RubyGems 3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.3.4 and Bundler 2.2.33, 2.3.0, 2.3.1, 2.3.2, 2.3.3, 2.3.4.

With this batch of…

Code with Jason 

129 - Drew Bragg, Staff Engineer at Within3

In this episode I talk with Drew Bragg about the Sin City Ruby conference, deciding what to spend your learning time on, Drew's time at Within3, missing objects, conceptualizing technical debt, and object-oriented principles.

Rails, PostgreSQL Performance Audit and Tuning Consultant for Hire 

Five Easy to Miss PostgreSQL Query Performance Bottlenecks

PostgreSQL query planner is full of surprises, so a common-sense approach to writing performant queries is sometimes misleading. In this blog post, I’ll describe examples of optimizing seemingly obvious queries with the help of EXPLAIN ANALYZE and Postgres metadata analysis.

All the test queries were performed on PostgreSQL 12 on a table seeded to one million objects. If you’d like to replicate similar behavior with a smaller development dataset, you’ll have to discourage the use of sequential scans by running:

SET enable_seqscan TO off;

This tutorial assumes some basic familiarity with reading the EXPLAIN ANALYZE reports. You can check out this blog post for an introduction to the topic.

Saeloun Blog 

Rails 7 allows setting timestamps on insert_all/upsert_all record creation

ActiveRecord is one of the most useful utilities in the Rails toolkit. It allows us to perform complex database queries while abstracting the adapter, essentially making a database “pluggable”.

However, some edge cases stand out like a sore thumb. One such query is the ability to set values to the standard Rails timestamps which are available across models. Namely, created_at, created_on, updated_at, updated_on.

In a typical model insertion, one does not need to actively set values for the timestamps. They are set by the underlying framework at the time of insertion.

> Book.create(title: "Ruby on Rails Tutorial: Learn Web Development with Rails")

> Book.last.created_at
=> Tue, 18 Jan 20…

Before

One would expect consistent action across similar queries. Let’s have a look at mass insertion…

RubyGems Blog 

December 2021 RubyGems Updates

Welcome to the RubyGems monthly update! As part of our efforts at Ruby Central, we publish a recap of the work that we’ve done the previous month. Read on to find out what updates were made to RubyGems and RubyGems.org in December.

RubyGems News

In December, we released new versions for RubyGems 3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.3.4 and Bundler 2.2.33, 2.3.0, 2.3.1, 2.3.2, 2.3.3, 2.3.4.

With this batch of releases, we finally shipped the Bundler version switching feature, which had been planned for some time now, and provided final versions to be included with new Ruby 3.1 release.

This month, Rubygems gained 209 new commits, contributed by 18 authors. There were 1825 additions and 1086…

Long Live Ruby 

SOLID principles

I’m sure you heard about SOLID principles at least one time. It’s also highly possible that you are sick of it. However, this topic is a pretty common thing during interviews, and besides that can help you design classes in a more readable, testable, and extendable way. This article is a quick summary easy to memorize, so you will never wonder again what this SOLID term is all about.
The Bike Shed 

322: Toxic Traits

Happy New Year (for real)! Chris and Steph both took some end-of-year time off to rest and recharge.

Steph talks about some books she enjoyed, recipes she tried, and trail-walking adventures with her dog, Utah. Chris' company is now in a good position to actually start hiring within the engineering team. He's excited about that and will probably delve into more around the hiring process in the coming weeks.

Since they aren't really big on New Year's Eve resolutions, Steph and Chris answer a listener question regarding toxic traits inspired by the listener question related to large pull requests and reflect on their own.

BigBinary Blog 

Rails 7 adds only_numeric option to numericality validator

Rails 7.0.1 introduces only_numeric option to numericality validator whichspecifies whether the value has to be an instance of Numeric. The defaultbehavior is to attempt parsing the value if it is a String.

When the database field is a float column, the data will get serialized to thecorrect type. In the case of a JSON column, serialization doesn't take place.

As a resolution, Rails 7 has added only_numeric option to numericalityvalidator.

We will see it in action.

To demonstrate, we need to generate a table that has a json/jsonb column.

# migrationcreate_table :users do |t|  t.jsonb :personalend

Before Validation

# Modelclass User < ApplicationRecord  store_accessor :personal, %i[age tooltips]end
Rémi Mercier 

Build a minimal feature flags manager in under an hour

When you deploy your code continuously, feature flags (or feature toggles) are a neat way to hide in-progress features from your users. In the past, I’ve written about my process for releasing large features. But after using feature flags in the last six months, I’ve come to like them better than my former process.

Still, hiding behavior behind if ENV['MY-FEATURE'].present?-type conditionals bothers me.

First, I don’t think the syntax is very legible. Second, I know it’s hard to maintain a naming convention across a team. You’ll soon end up with endless variations: ENV['MY-FEATURE], ENV[FF-MY-FEATURE-NAME], ENV['TOGGLE-FEATURE'], etc… These discrepancies make it hard to keep track of all…

Sure, you could use a gem or a third-party…

Mike Perham 

🎉 Happy 10th Birthday, Sidekiq! 🎂

It’s hard for me to believe these words but I pushed Sidekiq’s first commit on Jan 16th, 2012. Ten years ago. The public announcement. One month later. One quarter later. Some context for those new to this blog: Sidekiq is the most popular background job system for the Ruby programming language. Every application has tasks which are important: send an email, charge a credit card, reserve inventory for an order, synchronize some data to a 3rd party service, etc.
Kevin Newton 

Ruby Association Intermediate Report

In accordance with the Ruby Association’s timeline, this is an intermediate report on the Ruby formatter project.

Proposed work

When I first proposed the project, here are the list of deliverables that I mentioned in the proposal:

  • A definitive representation of the Ruby AST based on ripper. It would be an additional shipped ripper subclass (like Ripper::SexpBuilder and Ripper::SexpBuilderPP) with Ruby. The difference is that every node has location information available on it. It will also involve documentation of every node type being shipped along with the parser.
  • Updates and enhancements to the prettyprint gem. prettyprint does not currently support all of the various node types…
BootrAils 

ViteJS, Rails : a wonderful combination

0. Motivation

We are building BootrAils on top of the last Rails version. When Rails 7 came out, it was (kind of) a relief to see a replacement for Webpacker. Whereas the new assets pipeline looks better, it seemed that room for even better could exist somewhere.

The current frontend assets management of Ruby-on-Rails could feel hacky for many developers :

  • [live/auto/hot] reloading of HTML pages still doesn't work natively,
  • Serving assets with Rails has changed multiples times, from nothing (Sprockets appeared with Rails 3.1), to not-completely-ready importmaps. Currently Rails support jsbundling, that wraps esbuild (or optionally another tool...), before being injecting again to…
Honeybadger Developer Blog 

Monorepo Javascript Projects with Yarn Workspaces and Lerna

Monorepo is a software development strategy in which a single repository contains code for multiple projects with shared dependencies. It has a number of advantages:

  • It is easier to manage dependencies in monorepo projects. Common dependency versions are used, which saves a lot of time and computational power.
  • It is easier to refactor code across all packages.
  • Reusability of code is ensured.

And, like everything else in the world, the monorepo approach has certain disadvantages:

  • Including multiple versions of a dependency in different packages might cause dependency conflicts.
  • It degrades performance in version control systems, such as Git, due to higher memory usage.
  • Higher chances…

Tools Used to Set Up a Monorepo Project

  • Lerna is used to optimize the management of monorepos. We'll use this tool to manage shared…
Giant Robots Smashing Into Other Giant Robots 

Ruby Splat Operator 🌟

The Ruby splat operator is confusing and here is why: it does two things that are the exact opposite of each other. Let me explain…

Destructuring

It destructures an array, which looks something like this:

x, y, z = *[1,2,3]

puts x 
# => 1

puts y 
# => 2

puts z 
# => 3

Constructing

But it can also be used to construct an array:

x = *123
# => [123]

If you think about this, it is doing two very different things.

One takes an array and removes the surrounding square brackets [].

*[123] becomes 123

The other takes a value and adds the surrounding square brackets [].

*123 becomes [123]

When does it destruct and when does it construct?

The only…

Mike Coutermarsh 

Why infrastructure engineers prefer MySQL

For years I’ve been noticing this pattern of infrastructure engineers I really respect preferring MySQL and product engineers preferring Postgres.

It took quite a while for me to understand it. Especially coming from my background as a product engineer.

Different types of engineers value different things

Infrastructure engineers generally care most about reliability, failure scenarios, upgrades and never, ever, losing data. Product engineers care about that too, but they focus more on tools that make building user functionality easier.

When an infrastructure engineer tells you they prefer MySQL. It’s probably because for them it’s simpler/easier to operate it. Backups, replication,…

Notes to self 

Configuring Rails system tests for headless and headfull browsers

Want to run your system tests headless? And why not both ways? Here’s how to extend Rails tasks to run your system tests with the driver of your choice.

Rails 6 came with system tests baked-in, and so if you generate a new Rails app today, you end up with the following setup code:

# test/application_system_test_case.rb
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end

You’ll need some dependencies for this to work. If you don’t have them, add the following to your Gemfile:

# Gemfile
...
group :test do
  # Use system testing…
BilalBudhani 

Using Chokidar with Esbuild To Rebuild On Change

This month I was migrating from Webpacker to ESBuild using JSBundling in a client's Ruby on Rails project, since, they were using Stimulus & a couple of Javascript dependencies in the project, the migration went smoothly.

However, I realised that ESBuild doesn't watch for changes in the root project instead it only listens to the files mentioned in `entryPoints` config. This doesn't make it an ideal DX (developer experience), so I decided to dig deeper on how to get this experience right.

I found an issue on ESBuild repo a lot of folks have shared their approach to solve it. I picked the one that felt right for our use case, tweaked it a little bit to get what I want & kept is as simple as…

Justin Collins' Blugh 

DragonRuby: Object-Oriented Starter

I enjoy playing with the DragonRuby Game Toolkit, but the documentation and many of the examples are very much intended for non-Rubyists. Additionally, as a game engine, it’s more data/functionally-oriented than most Rubyists are used to. For example, the main game loop in the tick method needs to be implemented as a top-level method.

This post walks through structuring a game in a way that is a little more familiar to Rubyists.

Caveat! I am new to DragonRuby myself and this is not meant to be the “correct” or “best” or even “great” way to organize your code. It’s just a pattern I’ve started using and it might be useful for you!

(By the way, while DragonRuby is a commercial product, you…

EquiValent 

Order attachments in Rails ActiveStorage has_many_attached

Ruby on Rails Active Storage introduced bunch of cool features for uploading files. One large advantage is a simple way how to store multiple attachments for a model with has_many_attached but also ability to upload files with direct upload

has_many_attached is a cool feature but developers may feels like it’s missing one critical feature: change order of attachments.

In this article I’ll show you one simple way how to order attachments of a simple Entry model that has many pictures.

To limit the scope of this article I’ll assume your application have a basic setup of ActiveStorage such as bin/rails active_storage:install

Basic solution

Here is our Entry model. As you can see…

Julia Evans 

Some ways DNS can break

When I first learned about it, DNS didn’t seem like it should be THAT complicated. Like, there are DNS records, they’re stored on a server, what’s the big deal?

But with DNS, reading about how it works in a textbook doesn’t prepare you for the sheer volume of different ways DNS can break your system in practice. It’s not just caching problems!

So I asked people on Twitter for example of DNS problems they’ve run into, especially DNS problems that didn’t initially appear to be DNS problems. (the popular “it’s always DNS” meme)

I’m not going to discuss how to solve or avoid any of these problems in this post, but I’ve linked to webpages discussing the problem where I could find them.

pro…

Notes to self 

Maintainable Rails system tests with page objects

Rails system tests often depend on input and CSS selectors. To make our tests more maintainable, we can isolate layout changes within page objects.

This post is about an idea I had a long time ago and came back to recently. It’s from a similar category as my idea for Rails contexts, so it might not be 100% failproof, and I am looking for feedback.

So what is it about? What’s a page object?

A regular system test might look like this:

require "application_system_test_case"

class RegisterUserTest < ApplicationSystemTestCase
  setup do
    @user = users(:unregistered)
  end

  test "registers an account" do
    visit new_user_registration_path

    fill_in "Email", with: user.email
    fil…

It’s nice and tidy for something…

EquiValent 

Move position of item in Array up and down in Ruby lang

module ArrayElementMove
  MustBeUniqArray = Class.new(StandardError)
  ItemNotInArray  = Class.new(StandardError)

  def self.up!(array, item)
    self.check_if_uniq!(array)
    return array if array.first == item
    position = array.index(item) || raise(ItemNotInArray)
    array.insert((position - 1), array.delete_at(position))
  end

  def self.down!(array, item)
    self.check_if_uniq!(array)
    return array if array.last == item
    position = array.index(item) || raise(ItemNotInArray)
    array.insert((position + 1), array.delete_at(position))
  end

  def self.check_if_uniq!(array)
    raise MustBeUniqArray if array.size != array.uniq.size
  end
end
require 'spec_helper'
# …
Shopify Engineering - Shopify Engineering 

Search at Shopify—Range in Data and Engineering is the Future

Mike Coutermarsh 

Why not use the most “hype” stack?

Got a great question in Twitter DMs.

How do you stay motivated on working with boring/non-hype tech? I’m always hyped about a new stack and can’t make progress building a SAAS.

It’s hard out there. If you read twitter, hacker news, etc, there is always something new and better coming out. It’s distracting and many people are spinning their wheels rather than making progress towards their goals.

Answer this question: which would you rather have? A single index.php file that generates $10k a month? Or a React/GraphQL/Serverless app that has a lot of GitHub stars?

I’ll take the $10k.

Valuable engineers create business value with technology

Read that ^ multiple times and internalize…

Remote Ruby 

WNB.rb with Emily Giurleo & Jemma Issroff

[00:01:32] Emily and Jemma tell us their background stories of how they found their way into Ruby. 


[00:03:26] Andrew asks Emily and Jemma if they ever wrote in BlueJ and he explains what it is.


[00:04:19] We learn more about WNB.rb, how big the group is, and all the events they do.  Also, Jemma tells us about Emily’s talk she gave at RubyConf 2020 that’s worth checking out called, “The Bug that Forced Me to Understand Memory Compaction.” 


[00:11:29] As leaders of WNB.rb, Jason asks Emily and Jemma what their favorite experiences are that they’ve had so far.


[00:13:42] Find out some ways that people who don’t identify with women or non-binary can help with WNB.rb or even just help the…

Saeloun Blog 

Cypress 9.2.0 will throw an error when a user attempts to update a read-only config value

Cypress provides two options to override the configuration while the tests are running - Cypress.config() and suite-specific or test-specific configuration overrides.

Before

Before version 9.2.0, it was not documented which config options are readonly and which ones are writable at the runtime, which created a lot of confusion.

For example: If we were to change screenshotsFolder during test using Cypress.config():

describe('Test readonly config options', () => {
  it('updating screenshots location in version 8.7.0', () => {
    cy.visit('http://www.google.com')
    Cypress.config('screenshotsFolder', 'cypress/screenshots/desktop')
    expect(Cypress.config('screenshotsFolder')).to.eq('c…

The test mentioned above passes, but Cypress does not change the location of the screenshotsFolder, nor does it throw an error telling that the screenshotsFolder was not set.

Island94.org 

Javascript is a management problem

I have been on board with low/no javascript for a long time for a variety of observed and experienced reasons, and grasping around for a succinct explanation. Baldur Bjarnason captures it in “The Single-Page-App Morality Play”:

The problem is management.

It is a management problem. Truly.

The Multi-Page-App forces the team to narrow the scope to a level they can handle. It puts a hard limit on their technological aspirations. Mandating a traditional Multi-Page-App under the auspices of performance, accessibility, or Search-Engine-Optimisation is a face-saving way to force the hand of management to be more realistic about what their teams can accomplish. When we can accomplish the…

Awesome Ruby Newsletter 

💎 Issue 295 - Complete guide to setup VS Code for Ruby on Rails (Debugger, Autocomplete, Formatting)

zverok with ruby 

Following the programming language evolution, and taking it personally

Further adventures in understanding, explaining, and challenging the facts that should be obvious.
(Part 1Part 2Part 3)

There are characters in me who do not talk to each other who fill each other with grief who have never dined at the same table
[…] but I with all of my characters go on caring for you
— Garous Abdolmalekian, as heard on The Slowdown, ep. 395

I deeply believe in language’s evolution that is unstoppable, inevitable, and perpetual. Be it the human language or programming language—all the same.

However, this is not a universally accepted truth in many programming language communities. Especially for mature, widely-used languages like Java, Python, Ruby, and…

Ruby Weekly 

A history of compiling Ruby

#​586 — January 13, 2022

Read on the Web

Ruby Weekly

How a Routine Gem Update Ended Up Creating $73k of Accidental Subscriptions — The creators of a SaaS product noticed odd behavior after a seemingly innocuous update that exposed a major code smell in their source. I love this kind of transparency about production issues from our community, but it’s also a good example of being careful about your dependencies as the ground could move from beneath you..

Julien Khaleghy

Benchmarking CRuby, MJIT, YJIT, JRuby and TruffleRuby — A comparison of various Rubies across multiple benchmarks (such as optcarrot,…

Saeloun Blog 

Sneak peek into React 18 useDeferredValue hook

By default, React always renders a consistent UI. Usually, when we update the state, we expect to see changes on the screen without any delay. It makes the app feel responsive, giving us a better user experience.

However, sometimes it might be helpful to intentionally introduce an inconsistency.

Consider an example of switching tabs. While navigating from the Home tab to the Profile tab, we might see a blank page with a loader. It is because the profile page data is not loaded.

This becomes very frustrating, isn’t it?

It would have been better to stay on the Home page instead of seeing the blank page.

Before React 18, implementing this pattern was difficult. Thanks to the new…

BootrAils 

Ruby strftime, short and long story

strftime for the impatients

Sometimes examples worth a thousand words, so here are some that could help you right away (example inspired from APIDoks) :

d = DateTime.new(2021,11,19,8,37,48,"-06:00")
# => Fri, 19 Nov 2021 08:37:48 -0600
d.strftime("Printed on %m/%d/%Y")   
# => "Printed on 11/19/2021"
d.strftime("at %I:%M%p")
# => "at 08:37AM"

And a lot more of raw examples (explanations in paragraphs below)

%Y%m%d           => 20211119                  
%F               => 2021-11-19                
%Y-%m            => 2021-11                   
%Y               => 2021                      
%C               => 20                        
%Y%j             => 2021323                   
%Y-%j…
RubyGems Blog 

3.3.5 Released

RubyGems 3.3.5 includes enhancements, bug fixes and documentation.

To update to the latest RubyGems you can run:

gem update --system

To install RubyGems by hand see the Download RubyGems page.

## Enhancements:

  • Don’t activate yaml gem from RubyGems. Pull request #5266 by deivid-rodriguez
  • Let gem fetch understand <gem>:<version> syntax and --[no-]suggestions flag. Pull request #5242 by ximenasandoval
  • Installs bundler 2.3.5 as a default gem.

## Bug fixes:

  • Fix gem install <non-existent-gem> --force crash. Pull request #5262 by deivid-rodriguez
  • Fix longstanding gem install failure on JRuby. Pull request #5228 by deivid-rodriguez

## Documentation:

  • Markup Gem::Specificat…
Ruby – AWS Developer Tools Blog 

Developer Preview: Ruby SDK code generation using Smithy

What is this?

The AWS SDK For Ruby team is happy to announce the developer preview of smithy-ruby, a toolchain that can be used to code generate a “white label” Ruby SDK for your service API using Smithy modeling. An upcoming future version of the AWS SDK For Ruby will use Smithy code generation.

What is Smithy?

Smithy is an interface definition language and set of tools that allows developers to build clients and servers in multiple languages. Smithy models define a service as a collection of resources, operations, and shapes. A Smithy model enables API providers to generate clients and servers in various programming languages, API documentation, test automation, and example code. For…

Engine Yard Blog 

That's Not a Memory Leak, It's Bloat

Our Rails customers often run into memory issues. The most frequent cause these days is what we in Support dub ‘bloated mongrels.’

Code with Jason 

If you want to learn testing, first learn how to program in feedback loops

Most beginner programmers (and even many experienced programmers) take a slow, painful, wasteful approach to programming.

The wasteful way

The way many programmers code is to spend a bunch of time writing code without checking to see that it works, then finally run the program once they’ve accumulated many lines of code. The program inevitably fails.

Next, the programmer sits and puzzles over what might have gone wrong. Since the programmer wrote a lot of code without checking it, there’s a lot of stuff that could possibly be the culprit, and therefore the debugging process is slow and painful.

The debugging process is usually not a systematic one but rather a guessing game. “Maybe it’s…

Shopify Engineering - Shopify Engineering 

That Old Certificate Expired and Started an Outage. This is What Happened Next

Hanami 

Announcing Hanami v2.0.0.alpha5

Happy new year, Hanami community! To get 2022 started, we're excited to announce the release of Hanami 2.0.0.alpha5!

This release brings the last month of our work on Hanami 2.0 (with an extra week added for good measure, while we all returned from our end of year breaks). It includes:

  • Sensible default configuration for the application logger
  • Comprehensive source dirs configuration (for advanced users)
  • Lazy router and Rack app initialization
  • Access to the application route helpers from the view context
  • RSS support in our default MIME type list

Default application logger configuration

In our ongoing effort to strip boilerplate from our application template

The Ruby on Rails Podcast 

Episode 400: Nothing But Gold Stars All The Way with Collin Jilbert

Joining Brittany to celebrate episode 400(!), Collin Jilbert is a Ruby on Rails Developer at GoRails. They discuss why he committed to Rails so early in his career, his various ambitious projects (Ruby Radar, fleur de ruby), his love of the community and what his new role will entail.

Show Notes & Links:

Sponsored By:

Hook Relay

Hook Relay is a service that makes sending and receiving webhooks reliable, secure, and transparent—automatically. Sign up now, and you can start receiving webhooks from integrations like GitHub, etc.,…

Ruby Rogues 

Commanding Your Command Line with Adam Gordon Bell - RUBY 530

Ready to COMMAND your command line? Then listen up! In this episode, the Ruby Rogues sit down with Adam Gordon Bell, a software developer and host of the CoRecursive podcast. The guys discuss the tools that every developer MUST know in 2022, what users of Jekyll and Ruby can expect this year, and why Adam believes that JQ will save you hours from Google and Stack Overflow.

“I remember when I used to chase the “shiny new thing”, but now, I want to find the tools that last.”
- Adam Gordon Bell

In This Episode

The tools that every developer MUST know in 2022
What Adam learned from chasing the “shiny new thing” (and how you can avoid making the same mistake)
What people using Jekyll…

Greater Than Code 

266: Words Carry Power – Approaching Inclusive Language with Kate Marshall

01:48 - Kate’s Superpower: Empathy

  • Absorbing Energy
  • Setting Healthy Energetic Boundaries
  • Authenticity
  • Intent vs Impact

10:46 - Words and Narratives Carry Power; Approaching Inclusive Language

  • Taking Action After Causing Harm
  • Get Specific, But Don’t Overthink
  • Practice Makes Progress
  • Normalize Sharing Pronouns
  • Gender Expresion Does Not Always Equal Gender Identity

21:27 - Approaching Inclusive Language in the Written Word

29:18 - Creating Safe Places, Communities, and Environments

  • Absorbing and Asking
  • Authenticity (Cont’d)
  • Adaptation to Spaces
  • Shifting Energy

42:34…

Saeloun Blog 

Rails 7 adds better support for custom enum types in PostgreSQL

PostgreSQL provides in-built support for enumerated types that Rails can then take advantage of. However, it is often a pain to make use of this feature since it’s tedious to create custom enum types in PostgreSQL via ActiveRecord migrations.

Before

The previous method of creating custom enum types is done by executing direct SQL statements.

# db/migrate/*_create_articles.rb
def up
  execute <<-SQL
    CREATE TYPE status AS ENUM ('draft', 'published', 'archived', 'trashed');
  SQL

  create_table :articles do |t|
    t.column :current_status, :status
  end
end

Arguably this is not convenient in reality!

After

Often many Rails + PostgreSQL developers use structure.sql instead of schema…

RubySec 

CVE-2021-43846 (solidus_frontend): CSRF forgery protection bypass in solidus_frontend

### Impact CSRF vulnerability that allows a malicious site to add an item to the user's cart without their knowledge. All `solidus_frontend` versions are affected. If you're using your own storefront, please, follow along to make sure you're not affected. To reproduce the issue: - Pick the id for a variant with available stock. From the rails console: ```ruby Spree::Variant.in_stock.pluck(:id) ``` Say we pick variant id `2`. - Launch your application, for instance, on `http://localhost:3000`: ```bash bin/rails server ``` - Open your browser dev tools. - Click on whatever link in your store. - Copy the value of the `Cookie` request header sent for the previous request from your…
RubySec 

CVE-2021-22569 (google-protobuf): A potential Denial of Service issue in protobuf-java

## Summary A potential Denial of Service issue in protobuf-java was discovered in the parsing procedure for binary data. Affected versions: All versions of Java Protobufs (including Kotlin and JRuby) prior to the versions listed below. Protobuf "javalite" users (typically Android) are not affected. ## Severity **High** - An implementation weakness in how unknown fields are parsed in Java. A small (~800 KB) malicious payload can occupy the parser for several minutes by creating large numbers of short-lived objects that cause frequent, repeated GC pauses. ## Proof of Concept For reproduction details, please refer to the oss-fuzz issue that identifies the specific inputs that exercise…
Karl’s blog 

Simulate geolocation with Capybara and Headless Chrome

I recently added a “Locate me” button to Film Chase, which uses the Geolocation API (specifically getCurrentPosition) to get the current geolocation of a users device. Clicking the “Locate me” button triggers some Javascript like this

getPosition() {
  navigator.geolocation.getCurrentPosition((position) => {
    this.filter(position.coords.latitude, position.coords.longitude);
  });
}

I was keen to add a feature specification to test this functionality

it 'allows a user to share their current geolocation', :js do
  visit root_path

  click_button 'Locate me'

  expect(page).to have_text 'Location: Oxford'
end

This test won’t work because thankfully headless Chrome isn’t configured by…

avdi.codes 

SIGAVDI #94: Belgian Coffee Edition

Hello friends,

It finally got cold here in St. Louis, albeit still with a sad paucity of snow. We got a dusting the other day.

I’m on the last day of a quarantine with my partner; she got a surprise positive COVID test the other day in prep for some travel. Neither of us is sick at all, so our vaccines and boosters probably did their job. But we’re being careful anyway.

Fortunately, the bison at Lone Elk Park, where we made a field trip to get out of the house, are not at risk of COVID. They abide.

Let’s do some bullets, shall we?

What’s Good

  • Anyone who cares about science and also about people has to struggle with teasing apart problematic scientists from…
Notes to self 

Single attribute in-place editing with Rails and Turbo

Turbo can largely simplify our front-end needs to achieve a single-page application feel. If you have ever wondered how to do a single attribute in-place update with Turbo, this post is for you.

I’ll assume you have Turbo (with turbo-rails gem) installed, and you already have a classic model CRUD done. If you don’t, just generate a standard scaffold. I’ll use the User model and the name attribute, but it can be anything.

At this point, you might have a controller for the model looking like this:

class UsersController < ApplicationController
  before_action :set_user, only: %i[ show edit update destroy ]

  ...

  # GET /users/1/edit
  def edit
  end

  # PATCH/PUT /users/1 or…
Code with Jason 

128 - Adrian Marin, Founder of Avo Admin

In this episode I'm joined by Adrian Marin for an in-depth discussion of his product Avo Admin. In addition to talking about Avo, we also talk about the Romanian language and Slavic versus Romance languages.

Julia Evans 

How to find a domain's authoritative nameservers

Here’s a very quick “how to” post on how to find your domain’s authoritative nameserver.

I’m writing this because if you made a DNS update and it didn’t work, there are 2 options:

  1. Your authoritative nameserver doesn’t have the correct record
  2. Your authoritative nameserver does have the correct record, but an old record is cached and you need to wait for the cache to expire

To be able to tell which one is happening (do you need to make a change, or do you just need to wait?), you need to be able to find your domain’s authoritative nameserver and query it to see what records it has.

But when I looked up “how to find a domain’s authoritative nameserver” to see what advice was out there,…

Saeloun Blog 

Ruby 3.1 adds Class#subclasses

We often come across situations where we need to inherit the characteristics of one class into another class. Inheritance ensures the “reusability” of codes as while creating a new class, we can derive some of the codes from the existing parent class. This is why Ruby 3.1 has added a new method called Class#subclasses. This returns all classes directly inheriting from the receiver without adding singleton classes.

We can use different implementations from Ruby via gems to calculate subclasses of a particular class. The ActiveSupport::DescendantsTracker is one of the implementations we use in Ruby on Rails. Finally, Ruby has introduced the Class#subclasses native implementation for its…

Key terms in Inheritance:

S…

Long Live Ruby 

Design Rails enums the right way

While it’s very easy to define enum and use all the dynamic methods provided by Rails, there are some things we should be aware of not to create data integrity problems and code that is hard to maintain. This article is a set of good practices for enums in Rails.
Notes to self 

Freezing your Node.js dependencies with yarn.lock and –frozen-lockfile

When Yarn introduced a lock file (similar to Gemfile.lock), it did it with an unexpected twist. If you need reproducible builds, yarn.lock is not enough.

What is a lock file? Lock files ensure that the defined dependencies from files such as package.json get pinned to specific versions. This later ensures parity on developers’ workstations, CI, and production.

Many people probably depend on Yarn doing the right thing and installing only the pinned versions from yarn.lock on yarn install. But, unfortunately, this is not the case…

The default behavior of yarn install is that the yarn.lock file gets updated if there is any mismatch between package.json and yarn.lock. Weird, right?

(In…

The Bike Shed 

321: Leaving Breadcrumbs

Steph tells a cute story about escape artist huskies, and on a technical note, shares a journey in regards to class variables and modules inheritance.

Chris talks about how he's starting to pursue analytics and one of the things that he's struggling with that he's always historically struggled with is the idea of historical data. He's also noticed a lack of formalization of certain things and is working with his team to remedy that.


This episode is brought to you by ScoutAPM. Give Scout a try for free today and Scout will donate $5 to the open source project of your choice when you deploy.


Benito Serna 

Inline CRUD with rails and hotwire

This is a guide to help you build “inline CRUDs” with rails and hotwire, where you create and edit records in the same page.

  • Instead of a “new product” page it shows the form in the same page
  • Instead of an “edit product” page it shows the form on the same page by replacing the product item.

Like in the next video…

The example app

You can find the code of the app in the video on: github/bhserna/inline_crud_hotwire

To explain how you can add this behavior to your app, I will use the app from the video as an example.

If you need help to extrapolate the example for your use case, you can ask a question in the comments section of this post, I will try to answer there.

Inline CRUD…

ruby – Bibliographic Wilderness 

Finding source install location of a loaded ruby gem at runtime

Not with a command line, but from within a ruby program, that has gems loaded … how do you determine the source install location of such a loaded gem?

I found it a bit difficult to find docs on this, so documenting for myself now that I’ve figured it out. Eg:

Gem.loaded_specs['device_detector'].full_gem_path
# => "/Users/jrochkind/.gem/ruby/2.7.5/gems/device_detector-1.0.5"
Graceful.Dev 

Site News #6: Resurrected comments and a better start page

Hey there graceful devs,

I hope this update finds you safe and healthy amidst this latest pandemic surge. Having nowhere to go but the home office has certainly given me plenty of time to work on Graceful.Dev. Here’s what’s new since the last update:

Content Updates

  • More o11y: The Introduction to Observability course by Jessica Kerr in partnership with Honeycomb, is moving ahead at full speed. Jess has added four new topics since the last update! Just as software needs production feedback to guide development, under-construction courses need student feedback to guide their evolution! So please do jump in and let Jess know what’s missing!
  • Comments imported: In the last update, I…
BootrAils 

Rails authentication with Rodauth, an elegant Ruby gem

0. Motivation

At BootrAils, until recently, we were uncomfortable about what could be a decent default authentication in any new Rails app - until Rodauth appeared under the radar.

There are no "Active Auth" in the Ruby-on-Rails world, which means if you want to add authentication in your app, you have to rely on a gem - or build it yourself.

For those who already know this field, this is an endless debate over the wild Internet. Devise is the most used gem. However, it always comes with "so-so" appreciations by long-term users : Devise is not so great for corner cases (handling JWT authentication is one of the complaints, amongst many others). Clearance, Sorcery are well-known…

Honeybadger Developer Blog 

Migrating From Turbolinks To Turbo

Turbolinks, a great tool to make navigating your web application faster, is no longer under active development. It has been superseded by a new framework called Turbo, which is part of the Hotwire umbrella.

The team behind it understood that other stuff could adopt similar concepts extracted from Turbolinks to adhere to a faster web, such as frames, forms submissions, and native apps.

This article aims to provide a guide for the Turbo framework, the new substitute for Turbolinks, including a practical migration guide that'll explain how to use the most important and commonly used pieces of Turbolinks in Turbo.

To better understand what we’ll talk about, it’s essential to have some…

Mike Coutermarsh 

When to cache in your Rails app

I’ve been working on Rails applications for over 10 years. In that time I’ve figured out some guidelines on when and when not to use caching.

Years ago, I’d cache almost everything. When joining GitHub, I remember being shocked by how little caching was actually used for such a high traffic app. It made me think, maybe I’ve been approaching this wrong?

Hardware and Rails are now faster

When I first started with Rails, CPU’s and Ruby were much slower. The rendering of views would often be a large factor in the over all request time. Caching the rendering of a view was almost always a big performance win.

This has changed. As Rails has gotten faster and the servers we run our apps on are…

Kevin Newton 

Ripper CHANGELOG 3.1.0

The Ripper module ships with the Ruby standard library and gets updated (implicitly or explicitly) every time the Ruby parser changes. Unfortunately, Ripper itself never changes version (it’s been stuck at 0.1.0 since it was first shipped with Ruby in 2004). As such, there isn’t really a dedicated CHANGELOG, and it’s somewhat difficult to determine what changed inside the Ripper module without digging into the source.

Because I maintain a couple of things that depend on Ripper’s interface, I have some insight into what goes down when Ripper updates. Because of this, I’m putting out this blog post with a list of the changes in the hope that it helps anyone else out there that may be using…

Justin Collins' Blugh 

DragonRuby: Static Outputs

In a previous post we looked at different ways to render outputs (sprites, rectangles, lines, etc.) in the DragonRuby Game Toolkit.

The post ended by hinting at a more efficient way to render outputs instead of adding them to e.g. args.outputs.solids or args.outputs.sprites each tick.

This post explores the world of “static outputs”!

Static What?

First of all, we should address the most confusing part of all this.

“Static” does not mean the images don’t move or change. Instead, it means that render “queue” is not cleared after every tick.

Normally, one would load up the queue each tick, like this:

1
2
3
4
5
6
7
8
9
10
def tick args

  # Render a black rectangle
  args.outputs.solids     x: 100,

But this is…

Mike Coutermarsh 

Running queries in parallel with Rails 7 and load_async

Rails 7 has added the load_async method to ActiveRecord. This looks like it could be a huge performance win for many Rails applications.

Normally, a Rails app will execute all of its queries serially (one after another). The execution of the request waits while the query is executed. With load_async, you can now send your queries to the background and let them execute while your foreground thread continues on with the request.

If you’re familiar with using something like Promise.all to execute several queries in a Node.js app at once. This works out to be fairly similar.

Example

I set up an intentionally slow example app that executes 4 queries to render a page. To simulate some latency,…

Saeloun Blog 

Ins and Outs of Profit Sharing

As we step into the financial year of 2022, we are pleased to announce that we will be sharing a portion of our annual profits with you, like the previous year.

This initiative has the purpose of allowing employees to feel a sense of ownership toward the company. We also hope this will motivate you to strive for even greater success in the future.

Our Profit Sharing scheme is already listed in Employment benefits, and in this blog post, we will discuss the nitty-gritty of this process and how we will compute the shares for the employees.

Why did we opt for Profit Sharing?

Profit-Sharing plans are considered a type of employee benefit by the Internal Revenue Service. In the…

Code with Jason 

Rails can only take you so far

Applications tend to grow over time. In the beginning of an application’s life, things are typically pretty easy. Rails provides “slots” for us to put our code in. Display-related code goes in the views. Domain logic and persistence-related logic go in the models. The code that connects the two goes in the controllers.

But over time the slots fill up. Models get bloated to hundreds or even thousands of lines. Models become miscellaneous grab bags of unrelated methods. Controllers get cluttered with custom actions and grow large and hard to understand. Entropy takes over and things become a mess.

At this point, many developers sadly head down a bad path. They observe that, early on, Rails…

Code with Jason 

How Ruby’s method_missing works

What we’re going to cover

In this post we’ll take a look at an example of the kinds of things you can do with method_missing as well as how and why method_missing works.

The example

The following example is a DSL which will allow us to construct an HTML document using Ruby.

(This example, by the way, is shamelessly stolen from a great post by Emmanuel Hayford who apparently himself took the example from the book The Ruby Programming Language. Check out the post and maybe the book too.)

Basic version

Here’s some Ruby code that will generate a rudimentary HTML document.

HTMLDocument.new do
  html do
    body do
      puts "Hello world"
    end
  end
end

The generated HTML code looks like this.

Tender Lovemaking 

Homebrew, Rosetta, and Ruby

Hi everyone! I finally upgraded to an M1. It’s really really great, but the main problem is that some projects I work on like TenderJIT and YJIT only really work on x86_64 and these new M1 machines use ARM chips. Fortunately we can run x86_64 software via Rosetta, so we can still do development work on x86 specific software.

I’ve seen some solutions for setting up a dev environment that uses Rosetta, but I’d like to share what I did.

Installing Homebrew

I think most people recommend that you install two different versions of Homebrew, one that targets ARM, and the other that targets x86.

So far, I’ve found this to be the best solution, so I went with it. Just do the normal Homebrew…

Ruby Rogues 

What's New in Rails 7 with Stefan Wienert - RUBY 529

With all this hype around Rails 7, how do you ACTUALLY use it? And is it better than its predecessors? In this episode, the Ruby Rogues sit down with Stefan Wienert, a software developer whose passion for Ruby and technical expertise speak for themselves. The group talks about how to avoid headaches in these new systems, the BEST way to encrypt your data, and plenty of details for navigating Ruby on Rails like you’ve always wanted to.

_“You can jump in and fix it right away. It’s very dangerous and very powerful, so it’s great that they have this kind of gem. I’m really excited to about it.”

  • Stefan_

In This Episode:

Stefan’s perspective on cssbundling and jsbundling vs.…

Code with Jason 

“Am I smart enough for programming?”

Sometimes on programming forums someone asks a question along the lines of, “Am I smart enough for programming?”

The bad answer

Typically the answers to this question are some variation of “Yes! Keep going! You can do it!”

These answers are well-intentioned but not honest. The answerer has no idea who the asker is or how smart they are. That’s like someone asking, “Am I tall enough to ride a rollercoaster?” and people answering, “Yes! You can do it! Just believe in yourself!” It’s not necessarily true, obviously. And it’s not helpful.

The good answer

When someone asks if they’re smart enough for programming, what they’re probably experiencing is that they’re spending a lot of time and…

John Nunemaker 

Rails: Postgres Native Partitioning

At Box Out and Flipper Cloud we've got some big tables. Not huge, but big (tens to hundreds of millions). I've been meaning to try pg_partman, pgslice or native postgres partitioning for a while. I finally did and as usual thought I should write it up for posterity.

pgslice

pgslice is pure ruby. That's cool (to me). But the gem's community is tiny compared to pg_partman and native postgres partitioning.

When making a decision on a dependency to use, always factor community in as a large percentage of why you choose what you do.

You likely don't want to maintain your choice long term or you wouldn't be looking for something that does it for you.

pg_partman

pg_partman is old and trusty. We used…

Remote Ruby 

Paul Bahr aka "Whats a GitHub?" aka "High School with Ashtrays"

[00:01:06] Paul tells us the story of how he got into audio editing and podcasting.


[00:05:19] We learn how Paul got linked up with the Remote Ruby podcast, as well as Brittany’s Ruby on Rails podcast. 


[00:09:01] Paul does True Crime podcasts and he tells us what he loves about them.


[00:09:31] Since Paul has edited many, many episodes for both of the podcasts, Brittany wonders if there are certain words that exist within the Ruby community.


[00:10:11] Brittany brings up the infamous Remote Ruby Episode 146, where Andrew starts off swearing for several minutes, and Andrew explains what happened.


[00:13:04] Paul shares tips and tricks on starting a new podcast, and advice on what you…

Ruby on Rails 

Rails 7.0.1 has been released

Hi everyone,

I am happy to announce that Rails 7.0.1 has been released. The focus of this release is bring support to Ruby 3.1, released last Christmas (December 25, 2021). This release also brings a few bug fixes and documentation improvements.

CHANGES since 7.0.0

To view the changes for each gem, please read the changelogs on GitHub:

To see a summary of changes, please read the release on…

Awesome Ruby Newsletter 

💎 Issue 294 - Comprehensive Ruby 3.1 changelog

EquiValent 

disable ElasticSearch security features are not enabled warning message

Given I’m using Ruby on Rails and ElasticSearch gem in localhost When any ElasticSearch update happens a warning message is logged:

warning: 299 Elasticsearch-7.16.2-2b937c44140b6559905130a8650c64dbd0879cfb "Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.16/security-minimal-setup.html to enable security."

To silence this add this line:

xpack.security.enabled: false

…to elasticsearch.yml

WARNING be sure this is only in your development machine NEVER IN PRODUCTION !!

e.g in OSx macbook this config file may be in:

/opt/homebrew/Cellar/elasticsea…
Jemma Issroff 

Hash#except in Ruby 3+

This was the tip of the week in the January 6, 2022 Ruby Weekly Newsletter.


If you’re an avid Rails user, you might be familiar with ActiveSupport’s Hash#except which has been around for roughly 15 years. As of Ruby 3.0, Hash#except is now a native Ruby method too!

But… what does it do? Hash#except gives us a hash excluding all of the keys we’ve passed as arguments. Let’s look at an example:

jemma = { name: "Jemma", username: "jemma", password: "super secure" }

jemma.except(:password)
# => { name: "Jemma", username: "jemma" }

Before Ruby 3.0, if we were in a repo which wasn’t using Rails, we could have done something like this:

jemma = { name: "Jemma", username: "jemma", password: 
zverok with ruby 

What you can learn by merely writing a programming language changelog

Adventures in understanding, explaining, and challenging the facts that should be obvious. (Part 1Part 2Part 3)

This article is written for my Substack, you can subscribe to it by email now!

First of all: I am deeply fond of Ruby-the-language. I have strong and frequently harsh (probably harsher than yours!) opinions on Ruby-the-tool in its current prevalent usage and some frameworks and practices associated with it. But the language—after 17 years of everyday use—is still incredibly helpful for my thought process, and I only half-jokingly call it my mother tongue. At least when thinking of the problems that could be formalized.

So, I understand the text below might be read as…

Ruby Weekly 

The gift of Ruby 3.1

🗓 We're back! And, no, you didn't miss a special Xmas edition of the newsletter, as I decided to enjoy the week off ;-) Unsurprisingly this issue focuses on the Ruby 3.1 release but Jemma is also back with a new Tip of the Week at the end of the issue, so we hope you enjoy that too :-)
__
Peter Cooper — Editor

#​585 — January 6, 2022

Read on the Web

Ruby Weekly

🎁  Ruby 3.1.0 Released on Christmas Day — As is traditional for Ruby, we got a significant new release on Christmas Day, although I was too busy eating turkey to notice at the time. The most exciting addition this time is YJIT, the latest attempt at adding…

On the Edge of Ruby 

Benchmarking CRuby, MJIT, YJIT, JRuby and TruffleRuby

In this blog post we benchmark many Ruby versions and the latest Ruby Just-in-Time compilers (JITs) on the newest Ruby benchmark suite, yjit-bench. As a teaser, the geometric mean speedups compared to CRuby 3.1 on these 14 benchmarks are: MJIT 1.26x, YJIT 1.39x, JRuby 1.86x and TruffleRuby 6.23x. Read on to find more about the benchmarks and gain insights on these speedups. This blog post is also available on Medium.

Outline

Approach

Rubies

We benchmark the following Ruby versions:

  • CRuby 2.0: ruby 2.0.0p648 (2015-12-16 revision 53162) [x86_64-linux]
  • CRuby 2.7: ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
  • CRub…
Saeloun Blog 

What's New in Tailwind CSS v3?

The first version of Tailwind CSS v3 is released, and it has loads of interesting features to explore. This version comes with several new utilities, variants, and many more that can enhance performance, workflows and save a lot of our time.

To jump right in and start using it, we have to install it via npm-

npm install -D tailwindcss@3

We need to update the @tailwindcss/typography or @tailwindcss/forms packages, as well, by using-

npm install -D @tailwindcss/typography@next

npm install -D @tailwindcss/forms@next

Just-in-Time engine by default

With version 3.0, the Just-In-Time (JIT) engine is the new default engine that enables the functioning of Tailwind CSS.

Before

The older…

BootrAils 

Ruby Enumerator : the what, the why, the how

What are Enumerators ?

This section will give you a general understanding of a few important terms and their distinctions. Before we start using them, we need to understand the concept of Enumeration and the tools Ruby gives us for Enumeration. Also, we will be assuming that you are comfortable with blocks in Ruby.

Enumeration, The Enumerable Module and Enumerator

Enumeration: As a concept simply means to traverse a list of items according to some logic. In programming, we often come across lists and the need to traverse these lists is a common programming necessity.

Enumerable: When using lists we commonly use either the for loop or the .each method to iterate over the items in them. We…

Justin Collins' Blugh 

API Levels in DragonRuby Game Toolkit

DragonRuby Game Toolkit (DRGTK) is a 2D game engine built with mRuby, SDL, and LLVM. It’s meant to be tiny, fast, and allow you to turn out games quickly using Ruby.

Unfortunately, since the documentation is focused on making games quickly, I sometimes get lost when trying to figure out how to do things that should be simple. DragonRuby seems to have borrowed Perl’s ”There’s more than one way to do it” philosophy because for anything you want to do with the API there are several ways to do it.

The documentation and examples tend to focus on the simplest forms (which is fine) but then require digging and experimentation to figure out the rest.

To help explain/document the different API…

Justin Collins' Blugh 

API Levels in DragonRuby Game Toolkit

DragonRuby Game Toolkit (DRGTK) is a 2D game engine built with mRuby, SDL, and LLVM. It’s meant to be tiny, fast, and allow you to turn out games quickly using Ruby.

Unfortunately, since the documentation is focused on making games quickly, I sometimes get lost when trying to figure out how to do things that should be simple. DragonRuby seems to have borrowed Perl’s ”There’s more than one way to do it” philosophy because for anything you want to do with the API there are several ways to do it.

The documentation and examples tend to focus on the simplest forms (which is fine) but then require digging and experimentation to figure out the rest.

To help explain/document the different API…

Ruby Changes 

Ruby 3.1

Highlights:

The first major release after 3.0, Ruby 3.1 mostly dedicated to stabilizing new features like concurrency and pattern-matching, but also introduces a bunch of new features.

  • Hash literal value omission
  • Anonymous block argument
  • Pattern-matching: pinning of expressions
  • Time: better support for timezones in construction
  • Low-level IO::Buffer
  • More methods become async with fiber scheduler

See also my this year’s ongoing post series on the making of the changelog and Ruby development process.

Read more »

Julia Evans 

Why might you run your own DNS server?

One of the things that makes DNS difficult to understand is that it’s decentralized. There are thousands (maybe hundreds of thousands? I don’t know!) of authoritative nameservers, and at least 10 million resolvers. And they’re running lots of different software! All these different servers running software means that there’s a lot of inconsistency in how DNS works, which can cause all kinds of frustrating problems.

But instead of talking about the problems, I’m interested in figuring out – why is it a good thing that DNS is decentralized?

why is it good that DNS is decentralized?

One reason is scalability – the decentralized design of DNS makes it easier to scale and more resilient to…

Martian Chronicles, Evil Martians’ team blog 

Our slice of the metaverse: 7 key AR features for iOS devs

Authors: Russ St Amant, iOS Engineer at Evil Martians and Travis Turner, Tech Editor at Evil Martians

Augmented and virtual worlds are expanding, and someday soon, people will do many of the things they currently do in real life inside of them. It’s easy to imagine all the exciting possibilities for entertainment, commerce, industrial applications, gaming, self-driving cars, just to name a few. Our mobile devices can certainly act as a personal plug-in to these augmented worlds, so let’s dive into Apple’s iOS AR frameworks and find out some of the awesome options that engineers have at their fingertips.

But before we get too augmented with our realities, let’s zoom back out a bit and…

Ruby Magic by AppSignal 

Next Level Ruby on Rails Application Monitoring with AppSignal

In the first of this two-part series, we covered how to set up AppSignal in a Ruby on Rails application for many great insights out of the box. AppSignal can automatically track errors, monitor performance, and report metrics about some dependencies.

But, in many cases, each of our applications behaves in different ways, so we'll want more than just generic monitoring.

In this post, we will run through adding custom instrumentation and monitoring to a Ruby on Rails application. This will give you deeper insights into how your application is behaving.

Prerequisites if you want to follow along with the code:

The Ruby on Rails Podcast 

Episode 399: New Year's Resolutions & Mediocrity with Brittany and Jemma

Will Ruby 3.1 drop on Christmas (spoiler: it did!)? Jemma and Brittany catch up with the changes from this past year, talk about some resolutions they are planning for 2022 and whether the pursuit for mediocrity should be one of them. Oh yes, they also touch on the release of Rails 7.

Show Notes & Links:

Sponsored By:

Hook Relay

Hook Relay is a service that makes sending and receiving webhooks reliable, secure, and transparent—automatically. Sign up now, and you can start receiving webhooks from integrations like GitHub, etc., even before you have an app to receive them.

S…