Today I Learned

hashrocket A Hashrocket project

Defaulting To Frozen String Literals

The cold never bothered me anyway.

The release of Ruby 2.2 introduced the ability to freeze string literals, making them immutable. With the release of Ruby 2.3, strings can be frozen by default without the use of #freeze. By adding the following magic comment at the top of a file

# frozen_string_literal: true

all string literals will default to frozen. That means that all string literals in that file are immutable, cannot be modified. This gives the Ruby interpreter some performance gains due to reduced object allocation.

This is the issue that introduced it.

See More #ruby TILs
Looking for help? Each developer at Hashrocket has years of experience working with Ruby applications of all types and sizes. We're an active presence at Ruby conferences, have written some of the most popular gems, and have worked on many of the web's Ruby on Rails success stories. Contact us today to talk about your Ruby project.