Method: Weak::Map#clone

Defined in:
lib/weak/map.rb

#clone(freeze: false) ⇒ Weak::Set

Weak::Map objects can’t be frozen since this is not enforced by the underlying ‘ObjectSpace::WeakMap` implementation. Thus, we try to signal this by not actually setting the `frozen?` flag and ignoring attempts to freeze us with just a warning.

Parameters:

  • freeze (Bool, nil) (defaults to: false)

    ignored; we always behave as if this is false. If this is set to a truethy value, we emit a warning.

Returns:

  • (Weak::Set)

    a new ‘Weak::Map` object containing the same elements as `self`


346
347
348
349
350
# File 'lib/weak/map.rb', line 346

def clone(freeze: false)
  warn("Can't freeze #{self.class}") if freeze

  super(freeze: false)
end