Class: Datadog::Core::Utils::ObjectSet
- Inherits:
-
Object
- Object
- Datadog::Core::Utils::ObjectSet
- Defined in:
- lib/datadog/core/utils/object_set.rb
Overview
Acts as a unique dictionary of objects
Direct Known Subclasses
Instance Method Summary collapse
-
#fetch(*args) ⇒ Object
Submit an array of arguments that define the message.
- #freeze ⇒ Object
-
#initialize(seed = 0, &block) ⇒ ObjectSet
constructor
You can provide a block that defines how the key for this message type is resolved.
- #length ⇒ Object
- #objects ⇒ Object
Constructor Details
Instance Method Details
#fetch(*args) ⇒ Object
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.
22 23 24 25 26 |
# File 'lib/datadog/core/utils/object_set.rb', line 22 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 ⇒ Object
36 37 38 39 |
# File 'lib/datadog/core/utils/object_set.rb', line 36 def freeze super @items.freeze end |
#length ⇒ Object
28 29 30 |
# File 'lib/datadog/core/utils/object_set.rb', line 28 def length @items.length end |
#objects ⇒ Object
32 33 34 |
# File 'lib/datadog/core/utils/object_set.rb', line 32 def objects @items.values end |