Skip to content

Instantly share code, notes, and snippets.

@electron0zero
Created October 15, 2019 09:27
Show Gist options
  • Save electron0zero/5258149307ef6e68c62c32c4d61962fa to your computer and use it in GitHub Desktop.
Save electron0zero/5258149307ef6e68c62c32c4d61962fa to your computer and use it in GitHub Desktop.
Example of Ruby class attribute to store BGThreadPool metrics
class BGThreadPoolT
# class attribute to store BGThreadPool metrics
class_attribute :metrics
# @note don't set this in code, it should only be set once on load
# setting it again will result in loss of metrics
self.metrics = Concurrent::Array.new
def add_things
self.class.metrics << "test #{self.object_id}"
return nil
end
end
b1 = BGThreadPoolT.new
b1.add_things
b2 = BGThreadPoolT.new
b2.add_things
b2.add_things
b2.add_things
ap BGThreadPoolT.metrics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment