class StringPool
- StringPool
- Reference
- Object
Overview
A string pool is a collection of strings. It allows a runtime to save memory by preserving strings in a pool, allowing to reuse an instance of a common string instead of creating a new one.
NOTE To use StringPool
, you must explicitly import it with require "string_pool"
require "string_pool"
pool = StringPool.new
a = "foo" + "bar"
b = "foo" + "bar"
a.object_id # => 136294360
b.object_id # => 136294336
a = pool.get(a)
b = pool.get(b)
a.object_id # => 136294312
b.object_id # => 136294312