Class: Datadog::Utils::ObjectSet
- Inherits:
-
Object
- Object
- Datadog::Utils::ObjectSet
- Defined in:
- lib/ddtrace/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.
20 21 22 23 24 |
# 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 ⇒ Object
34 35 36 37 |
# File 'lib/ddtrace/utils/object_set.rb', line 34 def freeze super @items.freeze end |
#length ⇒ Object
26 27 28 |
# File 'lib/ddtrace/utils/object_set.rb', line 26 def length @items.length end |
#objects ⇒ Object
30 31 32 |
# File 'lib/ddtrace/utils/object_set.rb', line 30 def objects @items.values end |