weak 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) Holger Just
4
+ #
5
+ # This software may be modified and distributed under the terms
6
+ # of the MIT license. See the LICENSE.txt file for details.
7
+
8
+ ##
9
+ module Weak
10
+ # The {Weak} version as a `Gem::Version` string. We follow semantic
11
+ # versioning.
12
+ # @see https://semver.org/
13
+ VERSION = "0.1.0"
14
+ end
data/lib/weak.rb ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) Holger Just
4
+ #
5
+ # This software may be modified and distributed under the terms
6
+ # of the MIT license. See the LICENSE.txt file for details.
7
+
8
+ require "singleton"
9
+
10
+ require_relative "weak/version"
11
+ require_relative "weak/map"
12
+ require_relative "weak/set"
13
+
14
+ # Weak is a Ruby library which implements collections of unordered values
15
+ # without strong object references.
16
+ #
17
+ # We provide multiple classes which behave similar to their standard-library
18
+ # counterparts. However, all elements are only weakly referenced. That way, all
19
+ # elements can be garbage collected and silently removed from the collection
20
+ # unless they are still referenced from some other live object.
21
+ module Weak
22
+ # A class for the {UNDEFINED} object. Being a singleton, there will only be
23
+ # exactly one object of this class: the {UNDEFINED} object.
24
+ #
25
+ # @private
26
+ class UndefinedClass
27
+ include Singleton
28
+
29
+ def initialize
30
+ freeze
31
+ end
32
+
33
+ # @return [String] the string `"UNDEFINED"`
34
+ def to_s
35
+ "UNDEFINED"
36
+ end
37
+ alias_method :inspect, :to_s
38
+ end
39
+
40
+ # The {UNDEFINED} object can be used as the default value for method arguments
41
+ # to distinguish it from `nil`.
42
+ #
43
+ # @see https://holgerjust.de/2016/detecting-default-arguments-in-ruby/#special-default-value
44
+ UNDEFINED = UndefinedClass.instance
45
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weak
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Holger Just
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-03-14 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: |
13
+ The Weak library provides a Weak::Set class to store an unordered list of
14
+ objects and a Weak::Map class to store a key-value map. The collection
15
+ classes only hold weak references to all elements so they can be
16
+ garbage-collected when there are no more references left.
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - CODE_OF_CONDUCT.md
23
+ - LICENSE.txt
24
+ - README.md
25
+ - lib/weak.rb
26
+ - lib/weak/map.rb
27
+ - lib/weak/map/abstract_strong_keys.rb
28
+ - lib/weak/map/deletable.rb
29
+ - lib/weak/map/strong_keys.rb
30
+ - lib/weak/map/strong_secondary_keys.rb
31
+ - lib/weak/map/weak_keys.rb
32
+ - lib/weak/map/weak_keys_with_delete.rb
33
+ - lib/weak/set.rb
34
+ - lib/weak/set/strong_keys.rb
35
+ - lib/weak/set/strong_secondary_keys.rb
36
+ - lib/weak/set/weak_keys.rb
37
+ - lib/weak/set/weak_keys_with_delete.rb
38
+ - lib/weak/version.rb
39
+ homepage: https://github.com/meineerde/weak
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ rubygems_mfa_required: 'true'
44
+ homepage_uri: https://github.com/meineerde/weak
45
+ source_code_uri: https://github.com/meineerde/weak
46
+ changelog_uri: https://github.com/meineerde/weak/blob/main/CHANGELOG.md
47
+ documentation_uri: https://www.rubydoc.info/gems/weak/0.1.0
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 3.0.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.6.3
63
+ specification_version: 4
64
+ summary: Tools to use handle collections of weak-referenced values in Ruby
65
+ test_files: []