Class: Crystalball::MapGenerator::AllocatedObjectsStrategy::ObjectTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/crystalball/map_generator/allocated_objects_strategy/object_tracker.rb

Overview

Class to list object classes used during a block

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(only_of: ['Object']) ⇒ ObjectTracker

Returns a new instance of ObjectTracker.

Parameters:

  • only_of (Array<Module>) (defaults to: ['Object'])
    • classes or modules to watch on



13
14
15
16
# File 'lib/crystalball/map_generator/allocated_objects_strategy/object_tracker.rb', line 13

def initialize(only_of: ['Object'])
  @only_of = only_of
  @created_object_classes = Set.new
end

Instance Attribute Details

#only_ofObject (readonly)

Returns the value of attribute only_of.



10
11
12
# File 'lib/crystalball/map_generator/allocated_objects_strategy/object_tracker.rb', line 10

def only_of
  @only_of
end

Instance Method Details

#used_classes_during { ... } ⇒ Array<Object>

Returns classes of objects allocated during the block execution.

Yields:

  • a block to execute

Returns:

  • (Array<Object>)

    classes of objects allocated during the block execution



20
21
22
23
24
# File 'lib/crystalball/map_generator/allocated_objects_strategy/object_tracker.rb', line 20

def used_classes_during(&block)
  self.created_object_classes = Set.new
  trace_point.enable(&block)
  created_object_classes
end