Class: TinyStruct::ObjectSpaceCache
- Inherits:
-
Object
- Object
- TinyStruct::ObjectSpaceCache
- Defined in:
- lib/tiny_struct/object_space_cache.rb
Overview
Allows for finding previously constructed TinyStruct classes that contain a certain set of members so that they do not end up getting created twice.
This cache saves some on space because we’re not storing them in memory, but takes a slight hit to performance whenever a new class in defined.
Instance Method Summary collapse
Instance Method Details
#[](members) ⇒ Object
10 11 12 13 14 |
# File 'lib/tiny_struct/object_space_cache.rb', line 10 def [](members) ObjectSpace.each_object(TinyStruct.singleton_class).detect do |clazz| clazz != TinyStruct && clazz.members == members end end |
#[]= ⇒ Object
8 |
# File 'lib/tiny_struct/object_space_cache.rb', line 8 def []=(*); end |