class Datadog::Utils::ObjectSet
Acts as a unique dictionary of objects
Public Class Methods
new(seed = 0, &block)
click to toggle source
You can provide a block that defines how the key for this message type is resolved.
# File lib/ddtrace/utils/object_set.rb, line 10 def initialize(seed = 0, &block) @sequence = Utils::Sequence.new(seed) @items = {} @key_block = block end
Public Instance Methods
fetch(*args) { |next, *args| ... }
click to toggle source
Submit an array of arguments that define the message. If they match an existing message, it will return the matching object. If it doesn't match, it will yield to the block with the next ID & args given.
# File lib/ddtrace/utils/object_set.rb, line 20 def fetch(*args) # TODO: Array hashing is **really** expensive, we probably want to get rid of it in the future key = @key_block ? @key_block.call(*args) : args.hash @items[key] ||= yield(@sequence.next, *args) end
freeze()
click to toggle source
Calls superclass method
# File lib/ddtrace/utils/object_set.rb, line 34 def freeze super @items.freeze end
length()
click to toggle source
# File lib/ddtrace/utils/object_set.rb, line 26 def length @items.length end
objects()
click to toggle source
# File lib/ddtrace/utils/object_set.rb, line 30 def objects @items.values end