123456789_123456789_123456789_123456789_123456789_

Class: TZInfo::StringDeduper Private

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
TZInfo::ConcurrentStringDeduper
Inherits: Object
Defined in: lib/tzinfo/string_deduper.rb

Overview

Maintains a pool of String instances. The #dedupe method will return either a pooled copy of a given String or add the instance to the pool.

Class Attribute Summary

Class Method Summary

Instance Method Summary

Class Attribute Details

.globalStringDeduper (readonly)

Returns:

  • (StringDeduper)

    a globally available singleton instance of StringDeduper. This instance is safe for use in concurrently executing threads.

[ GitHub ]

  
# File 'lib/tzinfo/string_deduper.rb', line 16

attr_reader :global

Instance Method Details

#create_hash(&block) ⇒ Hash (protected)

Creates a Hash to store pooled String instances.

Parameters:

  • block (Proc)

    Default value block to be passed to Hash.new.

Returns:

  • (Hash)

    a Hash to store pooled String instances.

[ GitHub ]

  
# File 'lib/tzinfo/string_deduper.rb', line 41

def create_hash(&block)
  Hash.new(&block)
end

#dedupe(string) ⇒ bool

Parameters:

  • string (String)

    the string to deduplicate.

Returns:

  • (bool)

    string if it is frozen, otherwise a frozen, possibly pre-existing copy of string.

[ GitHub ]

  
# File 'lib/tzinfo/string_deduper.rb', line 30

def dedupe(string)
  return string if string.frozen?
  @strings[string]
end