Skip to content

Commit e122edd

Browse files
committed
Add Defaulting To Frozen String Literals as a ruby til
1 parent 5393ee7 commit e122edd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ _305 TILs and counting..._
209209
- [Comparing Arrays In RSpec](ruby/comparing-arrays-in-rspec.md)
210210
- [Construct A Constant From A String](ruby/construct-a-constant-from-a-string.md)
211211
- [Create an Array of Stringed Numbers](ruby/create-an-array-of-stringed-numbers.md)
212+
- [Defaulting To Frozen String Literals](ruby/defaulting-to-frozen-string-literals.md)
212213
- [Destructuring Arrays In Blocks](ruby/destructuring-arrays-in-blocks.md)
213214
- [Disassemble Some Codes](ruby/disassemble-some-codes.md)
214215
- [Double Splat To Merge Hashes](ruby/double-splat-to-merge-hashes.md)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Defaulting To Frozen String Literals
2+
3+
> The cold never bothered me anyway.
4+
5+
The release of Ruby 2.2 introduced the ability to freeze string literals,
6+
making them immutable. With the release of Ruby 2.3, strings can be frozen
7+
by default without the use of `#freeze`. By adding the following magic
8+
comment at the top of a file
9+
10+
```ruby
11+
# frozen_string_literal: true
12+
```
13+
14+
all string literals will default to frozen. That means that all string
15+
literals in that file are immutable, cannot be modified. This gives the Ruby
16+
interpreter some performance gains due to reduced object allocation.
17+
18+
This is the [issue](https://bugs.ruby-lang.org/issues/11473) that introduced
19+
it.

0 commit comments

Comments
 (0)