weak 0.1.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d9cec118afb4ce760b9f1881b0489f9e9b1954ad5c20727d8d1124f9d80027d
4
- data.tar.gz: f0fd0cef1c7ce6403fb12630b880cb262063bc759100cfc4a6c7896cd0721e98
3
+ metadata.gz: 1495109d765259effd2efb1f7d97c7ad7e71e060ecb1d8f8f6cd6386e3a4d93c
4
+ data.tar.gz: 73be12838b3bdb16f45215dd9b07152e798d62130ca0bdfbca999b57a21ae25d
5
5
  SHA512:
6
- metadata.gz: c91a2284ad2a25a96ede2f44fcb2e6ed94d08342d83fefe3096c867385369b5ad48977fea610f611894ed763e981cb1b424dd84c23471ba9fb9bc3c19941b8c4
7
- data.tar.gz: 2bfd81fc7bb755ee7156a30527478c745dd10e8fff4b5865af823b3726c7105302d446aea9afc3e8c5d4e51ce612e28005c98cb8af5b0a76f98891aa0313cf36
6
+ metadata.gz: 35c2aa978606c8c1bd1c83838e9eb418eba8e4bada89936675fcb82c6a6a24304da7e34a56b38cf2bab42fd0b682efcf2577c2fecb4fd2c7fb02344869ab3cfd
7
+ data.tar.gz: 47e6c245cfe310e9ad7b538028cac0e36531b3c856ac3ec6efbb66126ac5c51f26dbecc03a516eca9598f8c81f02de5e26a51c435cc2f40a86a7d39ff2253793
data/.yardopts ADDED
@@ -0,0 +1,12 @@
1
+ --protected
2
+ --no-private
3
+ --markup markdown
4
+ --title=Weak
5
+ --template default
6
+ --default-return undocumented
7
+ lib/**/*.rb
8
+ -
9
+ README.md
10
+ CHANGELOG.md
11
+ CODE_OF_CONDUCT.md
12
+ LICENSE.txt
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## [Unreleased]
4
+
5
+ ## [0.2.1] - 2025-12-27
6
+
7
+ - Fix typos in code documentation
8
+ - Ignore some unnecessary methods defined on some `Set` implementations in `set_spec`
9
+ - Run specs on JRuby 10 in Github Actions
10
+ - Retry TruffleRuby rspec runs on Github Actions to avoid random failures due to flakey GC.
11
+ - Extract UNDEFINED to its own file and require it where used.
12
+ - Add more details about the gem version in `Weak::Version`
13
+ - Handle object cycles in `pretty_print`.
14
+
15
+ ## [0.2.0] - 2025-04-09
16
+
17
+ - Add `Weak::Map#delete_if`
18
+ - Add `Weak::Map#keep_if`
19
+ - Add `Weak::Map#reject!`
20
+ - Add `Weak::Map#replace`
21
+ - Add `Weak::Map#select!`
22
+ - Add `Weak::Map#values_at`
23
+
3
24
  ## [0.1.0] - 2025-03-14
4
25
 
5
26
  - Initial version of `Weak::Set` to store an unordered collection of objects.
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Weak
2
2
 
3
3
  [![gem version badge](https://badge.fury.io/rb/weak.svg)](https://rubygems.org/gems/weak)
4
- [![CI status badge](https://github.com/meineerde/weak/actions/workflows/ci.yml/badge.svg)](https://github.com/meineerde/weak/actions/workflows/ci.yml)
5
- [![Coverage Status](https://coveralls.io/repos/github/meineerde/weak/badge.svg?branch=main)](https://coveralls.io/github/meineerde/weak?branch=main)
4
+ [![github repo badge](https://img.shields.io/badge/github-repo-blue?logo=github)](https://github.com/meineerde/weak)
6
5
 
7
6
  Weak is a Ruby library which implements collections of unordered values without strong object references.
8
7
 
@@ -38,11 +37,11 @@ set
38
37
  `Weak::Map` behaves similar to a `Hash` or an `ObjectSpace::WeakMap` in Ruby (aka. MRI, aka. YARV).
39
38
  Both keys and values are weak references, allowing either of them to be garbage collected. If either the key or the value of a pair is garbage collected, the entire pair will be removed from the `Weak::Map`.
40
39
 
41
- Compared to the `Set` class however, there are a few differences:
40
+ Compared to the `Hash` class however, there are a few differences:
42
41
 
43
42
  - Key and value references are weak, allowing each key-value pair to be garbage collected unless there is a strong reference to boith the key and the value somewhere else.
44
43
  - We do not necessarily retain the order of elements as they are inserted into the `Weak::Map`. You should not rely on a specific order.
45
- - Map membership is governed by object identity of the key rather than by using the `hash` and `eql?` methods of the elements. A `Weak::Map` thus works similat to a `Hash` marked as [compare_by_identity](https://docs.ruby-lang.org/en/3.4/Hash.html#method-i-compare_by_identity).
44
+ - Map membership is governed by object identity of the key rather than by using its `hash` and `eql?` methods. A `Weak::Map` thus works similar to a `Hash` marked as [compare_by_identity](https://docs.ruby-lang.org/en/3.4/Hash.html#method-i-compare_by_identity).
46
45
  - You can freely change both keys and values added to the `Weak::Map`.
47
46
 
48
47
  ```ruby
@@ -64,7 +63,7 @@ map
64
63
  Please refer to the documentation at:
65
64
 
66
65
  - [📘 Documentation](https://www.rubydoc.info/gems/weak)
67
- - [💥 Development Documentation](https://www.rubydoc.info/github/meineerde/weak/main) of the [main branch](https://github.com/meineerde/weak/tree/main)
66
+ - [💥 Development Documentation](https://www.rubydoc.info/github/meineerde/weak) of the [main branch](https://github.com/meineerde/weak/tree/main)
68
67
 
69
68
  > [!WARNING]
70
69
  > The Weak collections are not inherently thread-safe. When accessing a collection from multiple threads or fibers, you MUST use a mutex or another locking mechanism.
@@ -213,6 +212,9 @@ end
213
212
 
214
213
  ## Development
215
214
 
215
+ [![CI status badge](https://github.com/meineerde/weak/actions/workflows/ci.yml/badge.svg)](https://github.com/meineerde/weak/actions/workflows/ci.yml)
216
+ [![Coverage Status](https://coveralls.io/repos/github/meineerde/weak/badge.svg?branch=main)](https://coveralls.io/github/meineerde/weak?branch=main)
217
+
216
218
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
217
219
 
218
220
  [![code style: standard badge](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/standardrb/standard)
@@ -225,7 +227,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/meinee
225
227
 
226
228
  ## License
227
229
 
228
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
230
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
229
231
 
230
232
  ## Code of Conduct
231
233
 
@@ -34,9 +34,9 @@ module Weak
34
34
  private
35
35
 
36
36
  # This method is called during {#_get}. It generally needs to be
37
- # overwritten in a "sub"-mdule to automatically cleanup any internal data.
38
- # The implemented `auto_prune` method should quickly check if a prune is
39
- # necessary and then either call the `prune` method or return.
37
+ # overwritten in a "sub"-module to automatically cleanup any internal
38
+ # data. The implemented `auto_prune` method should quickly check if a
39
+ # prune is necessary and then either call the `prune` method or return.
40
40
  #
41
41
  # @return [void]
42
42
  def auto_prune
@@ -8,6 +8,7 @@
8
8
  require "set"
9
9
 
10
10
  require "weak/map/abstract_strong_keys"
11
+ require "weak/undefined"
11
12
 
12
13
  ##
13
14
  module Weak
@@ -8,6 +8,7 @@
8
8
  require "set"
9
9
 
10
10
  require "weak/map/abstract_strong_keys"
11
+ require "weak/undefined"
11
12
 
12
13
  ##
13
14
  module Weak
@@ -6,6 +6,7 @@
6
6
  # of the MIT license. See the LICENSE.txt file for details.
7
7
 
8
8
  require "weak/map/deletable"
9
+ require "weak/undefined"
9
10
 
10
11
  ##
11
12
  module Weak
@@ -5,6 +5,8 @@
5
5
  # This software may be modified and distributed under the terms
6
6
  # of the MIT license. See the LICENSE.txt file for details.
7
7
 
8
+ require "weak/undefined"
9
+
8
10
  ##
9
11
  module Weak
10
12
  class Map
data/lib/weak/map.rb CHANGED
@@ -5,10 +5,11 @@
5
5
  # This software may be modified and distributed under the terms
6
6
  # of the MIT license. See the LICENSE.txt file for details.
7
7
 
8
- require_relative "map/weak_keys_with_delete"
9
- require_relative "map/weak_keys"
10
- require_relative "map/strong_keys"
11
- require_relative "map/strong_secondary_keys"
8
+ require "weak/map/weak_keys_with_delete"
9
+ require "weak/map/weak_keys"
10
+ require "weak/map/strong_keys"
11
+ require "weak/map/strong_secondary_keys"
12
+ require "weak/undefined"
12
13
 
13
14
  ##
14
15
  module Weak
@@ -270,15 +271,14 @@ module Weak
270
271
  INSPECT_KEY = :__inspect_key__
271
272
  private_constant :INSPECT_KEY
272
273
 
273
- # @param maps [Array<#each_pair>] a list of maps which should be
274
- # merged into the new {Weak::Map}
274
+ # @param maps [Array<Weak::Map, Hash, #to_hash>] a list of maps which should
275
+ # be merged into the new {Weak::Map}
275
276
  # @return [Weak::Map] a new {Weak::Map} object populated with the given
276
277
  # objects, if any. With no argument, returns a new empty {Weak::Map}.
277
278
  # @example
278
279
  # hash = {foo: 0, bar: 1, baz: 2}
279
280
  # Weak::Map[hash]
280
281
  # # => #<Weak::Map {:foo=>0, :bar=>1, :baz=>2}>
281
-
282
282
  def self.[](*maps)
283
283
  Weak::Map.new.merge!(*maps)
284
284
  end
@@ -432,6 +432,26 @@ module Weak
432
432
  proc
433
433
  end
434
434
 
435
+ # Deletes every key-value pair from `self` for which the given block
436
+ # evaluates to a truthy value.
437
+ #
438
+ # If no block is given, an `Enumerator` is returned instead.
439
+ #
440
+ # @yield [key, value] calls the given block once for each key in the map
441
+ # @yieldparam key [Object] a key
442
+ # @yieldparam value [Object] the corresponding value
443
+ # @return [Enumerator, self] `self` if a block was given or an `Enumerator`
444
+ # if no block was given.
445
+ # @see reject!
446
+ def delete_if(&block)
447
+ return enum_for(__method__) { size } unless block_given?
448
+
449
+ each do |key, value|
450
+ delete(key) if yield(key, value)
451
+ end
452
+ self
453
+ end
454
+
435
455
  # @return [Boolean] `true` if `self` contains no elements
436
456
  def empty?
437
457
  size == 0
@@ -467,25 +487,45 @@ module Weak
467
487
 
468
488
  object_ids << object_id
469
489
  begin
470
- elements = to_a.sort_by! { |k, _v| k.__id__ }.to_h.inspect[1..-2]
471
- "#<#{self.class} {#{elements}}>"
490
+ elements = to_a.sort_by! { |k, _v| k.__id__ }.to_h
491
+ "#<#{self.class} #{elements}>"
472
492
  ensure
473
493
  object_ids.pop
474
494
  end
475
495
  end
476
496
  alias_method :to_s, :inspect
477
497
 
498
+ # Deletes every key-value pair from `self` for which the given block
499
+ # evaluates to a falsey value.
500
+ #
501
+ # If no block is given, an `Enumerator` is returned instead.
502
+ #
503
+ # @yield [key, value] calls the given block once for each key in the map
504
+ # @yieldparam key [String] a hash key
505
+ # @yieldparam value [Object] the corresponding hash value
506
+ # @return [Enumerator, self] `self` if a block was given, an `Enumerator`
507
+ # if no block was given.
508
+ # @see select!
509
+ def keep_if(&block)
510
+ return enum_for(__method__) { size } unless block_given?
511
+
512
+ each do |key, value|
513
+ delete(key) unless yield(key, value)
514
+ end
515
+ self
516
+ end
517
+
478
518
  # Returns the new {Weak::Map} formed by merging each of `other_maps` into a
479
519
  # copy of `self`.
480
520
  #
481
- # Each argument in other_maos must be respond to `each_pair`, e.g. a
482
- # {Weak::Map} or a `Hash`.
521
+ # Each argument in `other_maps` must be either a {Weak::Map}, a Hash object
522
+ # or must be transformable to a Hash by calling `each_hash` on it.
483
523
  #
484
524
  # With arguments and no block:
485
525
  #
486
526
  # - Returns a new {Weak::Map}, after the given maps are merged into a copy
487
527
  # of `self`.
488
- # - The given hashes are merged left to right.
528
+ # - The given maps are merged left to right.
489
529
  # - Each duplicate-key entry’s value overwrites the previous value.
490
530
  #
491
531
  # Example:
@@ -502,7 +542,7 @@ module Weak
502
542
  # With arguments and a block:
503
543
  #
504
544
  # - Returns `self`, after the given maps are merged.
505
- # - The given hashes are merged left to right.
545
+ # - The given maps are merged left to right.
506
546
  # - For each duplicate key:
507
547
  # - Calls the block with the key and the old and new values.
508
548
  # - The block’s return value becomes the new value for the entry.
@@ -526,8 +566,8 @@ module Weak
526
566
  # - Returns a copy of `self`.
527
567
  # - The block, if given, is ignored.
528
568
  #
529
- # @param other_maps [Array<#each_pair>] a list of maps which should be
530
- # merged into a copy of `self`
569
+ # @param other_maps [Array<Weak::Map, Hash, #to_hash>] a list of maps which
570
+ # should be merged into a copy of `self`
531
571
  # @yield [key, old_value, new_value] If `self` already contains a value for
532
572
  # a key, we yield the key, the old value from `self` and the new value
533
573
  # from the given map and use the value returned from the block as the new
@@ -551,15 +591,92 @@ module Weak
551
591
  end
552
592
  end
553
593
 
594
+ # @!visibility private
595
+ def pretty_print_cycle(pp)
596
+ pp.text "#<#{self.class} {#{"..." unless empty?}}>"
597
+ end
598
+
599
+ # Deletes every key-value pair from `self` for which the given block
600
+ # evaluates to a truethy value.
601
+ #
602
+ # Equivalent to {#delete_if}, but returns `nil` if no changes were made.
603
+ #
604
+ # If no block is given, an `Enumerator` is returned instead.
605
+ #
606
+ # @yield [key, value] calls the given block once for each key in the map
607
+ # @yieldparam key [Object] a key
608
+ # @return [Enumerator, self, nil] `self` if a block was given and some
609
+ # element(s) were deleted, `nil` if a block was given but no keys were
610
+ # deleted, or an `Enumerator` if no block was given.
611
+ # #see #delete_if
612
+ def reject!(&block)
613
+ return enum_for(__method__) { size } unless block_given?
614
+
615
+ deleted_anything = false
616
+ each do |key, value|
617
+ next unless yield(key, value)
618
+
619
+ delete(key)
620
+ deleted_anything = true
621
+ end
622
+
623
+ self if deleted_anything
624
+ end
625
+
626
+ # Replaces the contents of `self` with the contents of the given Hash-like
627
+ # object and returns `self`.
628
+ #
629
+ # If the given `map` defines a {#default} value or {#default_proc}, this
630
+ # will also replace the respective seting in `self`.
631
+ #
632
+ # @param map (see #_implicit)
633
+ # @return [self]
634
+ # @example
635
+ # map = Weak::Map[a: 1, b: 3, c: 1] #=> #<Weak::Map {a: 1, b: 3, c: 1}>
636
+ # map.replace({x: :y}) #=> #<Weak::Map {x: :y}>
637
+ # map #=> #<Weak::Map {x: :y}>
638
+ def replace(map)
639
+ initialize_copy(_implicit(map))
640
+ end
641
+
642
+ # Deletes every key-value pair from `self` for which the given block
643
+ # evaluates to a falsey value.
644
+ #
645
+ # Equivalent to {#keep_if}, but returns `nil` if no changes were made.
646
+ #
647
+ # If no block is given, an `Enumerator` is returned instead.
648
+ #
649
+ # @yield [key, value] calls the given block once for each key in the map
650
+ # @yieldparam key [Object] a key
651
+ # @yieldparam value [Object] the corresponding value
652
+ # @return [Enumerator, self, nil] `self` if a block was given and some
653
+ # element(s) were deleted, `nil` if a block was given but nothing was
654
+ # deleted, or an `Enumerator` if no block was given.
655
+ # @see keep_if
656
+ def select!(&block)
657
+ return enum_for(__method__) { size } unless block_given?
658
+
659
+ deleted_anything = false
660
+ each do |key, value|
661
+ next if yield(key, value)
662
+
663
+ delete(key)
664
+ deleted_anything = true
665
+ end
666
+
667
+ self if deleted_anything
668
+ end
669
+ alias_method :filter!, :select!
670
+
554
671
  # Merges each of `other_maps` into `self`; returns `self`.
555
672
  #
556
- # Each argument in other_maos must be respond to `each_pair`, e.g. a
557
- # {Weak::Map} or a `Hash`.
673
+ # Each argument in `other_maps` must be either a {Weak::Map}, a Hash object
674
+ # or must be transformable to a Hash by calling `each_hash` on it.
558
675
  #
559
676
  # With arguments and no block:
560
677
  #
561
678
  # - Returns self, after the given maps are merged into it.
562
- # - The given hashes are merged left to right.
679
+ # - The given maps are merged left to right.
563
680
  # - Each duplicate-key entry’s value overwrites the previous value.
564
681
  #
565
682
  # Example:
@@ -576,7 +693,7 @@ module Weak
576
693
  # With arguments and a block:
577
694
  #
578
695
  # - Returns `self`, after the given maps are merged.
579
- # - The given hashes are merged left to right.
696
+ # - The given maps are merged left to right.
580
697
  # - For each duplicate key:
581
698
  # - Calls the block with the key and the old and new values.
582
699
  # - The block’s return value becomes the new value for the entry.
@@ -600,8 +717,8 @@ module Weak
600
717
  # - Returns `self`.
601
718
  # - The block, if given, is ignored.
602
719
  #
603
- # @param other_maps [Array<#each_pair>] a list of maps which should be
604
- # merged into `self`
720
+ # @param other_maps [Array<Weak::Map, Hash, #to_hash>] a list of maps which
721
+ # should be merged into `self`
605
722
  # @yield [key, old_value, new_value] If `self` already contains a value for
606
723
  # a key, we yield the key, the old value from `self` and the new value
607
724
  # from the given map and use the value returned from the block as the new
@@ -618,7 +735,7 @@ module Weak
618
735
  missing = Object.new
619
736
 
620
737
  other_maps.each do |map|
621
- map.each_pair do |key, value|
738
+ _implicit(map).each_pair do |key, value|
622
739
  old_value = fetch(key, missing)
623
740
  value = yield(key, old_value, value) unless missing == old_value
624
741
  self[key] = value
@@ -626,7 +743,7 @@ module Weak
626
743
  end
627
744
  else
628
745
  other_maps.each do |map|
629
- map.each_pair do |key, value|
746
+ _implicit(map).each_pair do |key, value|
630
747
  self[key] = value
631
748
  end
632
749
  end
@@ -675,6 +792,25 @@ module Weak
675
792
  hash
676
793
  end
677
794
 
795
+ # Returns a new `Array` containing values for the given keys:
796
+ #
797
+ # map = Weak::Map[foo: 0, bar: 1, baz: 2]
798
+ # map.values_at(:baz, :foo)
799
+ # # => [2, 0]
800
+ #
801
+ # The default values are returned for any keys that are not found:
802
+ #
803
+ # map.values_at(:hello, :foo)
804
+ # # => [nil, 0]
805
+ #
806
+ # @param keys [Array<Object>] a list of keys
807
+ # @return [Array] an `Array` containing the values for the given keys if
808
+ # present or the default value if not. The order of the given `keys` is
809
+ # preserved.
810
+ def values_at(*keys)
811
+ keys.map { |key| self[key] }
812
+ end
813
+
678
814
  private
679
815
 
680
816
  # Callback method which is called on the new object during `dup` or `clone`
@@ -710,5 +846,21 @@ module Weak
710
846
  )
711
847
  end
712
848
  end
849
+
850
+ # @param map [Weak::Map, Hash, #to_hash] a {Weak::Map} or a Hash object or
851
+ # an object which can be converted to a `Hash` by calling `to_hash` on it
852
+ # @return [Weak::Map, Hash] either a `Weak::Map` or a `Hash` object
853
+ # converted from the given `map`
854
+ # @raise [TypeError] if the given `map` is not a {Weak::Map} and not a
855
+ # `Hash`, and could not ge converted to a Hash
856
+ def _implicit(map)
857
+ if Weak::Map === map || ::Hash === map
858
+ map
859
+ elsif (hash = ::Hash.try_convert(map))
860
+ hash
861
+ else
862
+ raise TypeError, "no implicit conversion of #{map.class} into #{self.class}"
863
+ end
864
+ end
713
865
  end
714
866
  end
data/lib/weak/set.rb CHANGED
@@ -561,7 +561,7 @@ module Weak
561
561
 
562
562
  # @!visibility private
563
563
  def pretty_print_cycle(pp)
564
- pp.text "#<#{self.class} {#{empty? ? "" : "..."}}>"
564
+ pp.text "#<#{self.class} {#{"..." unless empty?}}>"
565
565
  end
566
566
 
567
567
  # @param other [Weak::Set] a weak set
@@ -0,0 +1,35 @@
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
+ ##
11
+ module Weak
12
+ # A class for the {UNDEFINED} object. Being a singleton, there will only be
13
+ # exactly one object of this class: the {UNDEFINED} object.
14
+ #
15
+ # @private
16
+ class UndefinedClass
17
+ include Singleton
18
+
19
+ def initialize
20
+ freeze
21
+ end
22
+
23
+ # @return [String] the string `"UNDEFINED"`
24
+ def to_s
25
+ "UNDEFINED"
26
+ end
27
+ alias_method :inspect, :to_s
28
+ end
29
+
30
+ # The {UNDEFINED} object can be used as the default value for method arguments
31
+ # to distinguish it from `nil`.
32
+ #
33
+ # @see https://holgerjust.de/2016/detecting-default-arguments-in-ruby/#special-default-value
34
+ UNDEFINED = UndefinedClass.instance
35
+ end
data/lib/weak/version.rb CHANGED
@@ -7,8 +7,36 @@
7
7
 
8
8
  ##
9
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"
10
+ # Version information about {Weak}}. We follow semantic versioning.
11
+ module Version
12
+ # MAJOR version. It is incremented after incompatible API changes
13
+ MAJOR = 0
14
+ # MINOR version. It is incremented after adding functionality in a
15
+ # backwards-compatible manner
16
+ MINOR = 2
17
+ # PATCH version. It is incremented when making backwards-compatible
18
+ # bug-fixes.
19
+ PATCH = 1
20
+ # PRERELEASE suffix. Set to a alphanumeric string on any pre-release
21
+ # versions like beta or RC releases; `nil` on regular releases
22
+ PRERELEASE = nil
23
+
24
+ # The {Weak} version as a `Gem::Version` string. We follow semantic
25
+ # versioning.
26
+ # @see https://semver.org/
27
+ STRING = [MAJOR, MINOR, PATCH, PRERELEASE].compact.join(".").freeze
28
+
29
+ # @return [Gem::Version] the {Weak} version as a `Gem::Version` object
30
+ def self.gem_version
31
+ Gem::Version.new STRING
32
+ end
33
+
34
+ # @return [String] the Weak version as a `Gem::Version` string
35
+ def self.to_s
36
+ STRING
37
+ end
38
+ end
39
+
40
+ # (see Version::STRING)
41
+ VERSION = Weak::Version::STRING
14
42
  end
data/lib/weak.rb CHANGED
@@ -5,8 +5,6 @@
5
5
  # This software may be modified and distributed under the terms
6
6
  # of the MIT license. See the LICENSE.txt file for details.
7
7
 
8
- require "singleton"
9
-
10
8
  require_relative "weak/version"
11
9
  require_relative "weak/map"
12
10
  require_relative "weak/set"
@@ -19,27 +17,4 @@ require_relative "weak/set"
19
17
  # elements can be garbage collected and silently removed from the collection
20
18
  # unless they are still referenced from some other live object.
21
19
  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
20
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Holger Just
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-14 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: |
13
13
  The Weak library provides a Weak::Set class to store an unordered list of
@@ -18,6 +18,7 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".yardopts"
21
22
  - CHANGELOG.md
22
23
  - CODE_OF_CONDUCT.md
23
24
  - LICENSE.txt
@@ -35,6 +36,7 @@ files:
35
36
  - lib/weak/set/strong_secondary_keys.rb
36
37
  - lib/weak/set/weak_keys.rb
37
38
  - lib/weak/set/weak_keys_with_delete.rb
39
+ - lib/weak/undefined.rb
38
40
  - lib/weak/version.rb
39
41
  homepage: https://github.com/meineerde/weak
40
42
  licenses:
@@ -44,7 +46,7 @@ metadata:
44
46
  homepage_uri: https://github.com/meineerde/weak
45
47
  source_code_uri: https://github.com/meineerde/weak
46
48
  changelog_uri: https://github.com/meineerde/weak/blob/main/CHANGELOG.md
47
- documentation_uri: https://www.rubydoc.info/gems/weak/0.1.0
49
+ documentation_uri: https://www.rubydoc.info/gems/weak/0.2.1
48
50
  rdoc_options: []
49
51
  require_paths:
50
52
  - lib
@@ -59,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
61
  - !ruby/object:Gem::Version
60
62
  version: '0'
61
63
  requirements: []
62
- rubygems_version: 3.6.3
64
+ rubygems_version: 4.0.3
63
65
  specification_version: 4
64
- summary: Tools to use handle collections of weak-referenced values in Ruby
66
+ summary: Tools to handle collections of weakly-referenced values
65
67
  test_files: []