Class: ObjspaceHelpers

Inherits:
Object
  • Object
show all
Defined in:
lib/objspace_helpers/helpers.rb,
lib/objspace_helpers/version.rb

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

._address_of_obj(obj) ⇒ Object



40
41
42
43
# File 'ext/objspace_helpers/objspace_helpers.c', line 40

static VALUE oh_address_of_obj(VALUE self, VALUE obj)
{
  return PTR2FIX(obj);
}

._addresses_to_info(ary) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'ext/objspace_helpers/objspace_helpers.c', line 23

static VALUE oh_addresses_to_info(VALUE self, VALUE ary)
{
  VALUE hash, obj_addr, info_hash;
  long i;

  hash = rb_hash_new();

  for (i = 0; i < RARRAY_LEN(ary); i += 1) {
    obj_addr = rb_ary_entry(ary, i);
    info_hash = rb_hash_new();
    objspace_info(FIX2PTR(obj_addr), info_hash);
    rb_hash_aset(hash, obj_addr, info_hash);
  }

  return hash;
}

._dump_addressesObject



16
17
18
19
20
21
# File 'ext/objspace_helpers/objspace_helpers.c', line 16

static VALUE oh_dump_addresses(VALUE self)
{
  VALUE ary = rb_ary_new();
  rb_objspace_each_objects(collect_addresses, (void *)ary);
  return ary;
}

._obj_for_address(address) ⇒ Object



45
46
47
48
# File 'ext/objspace_helpers/objspace_helpers.c', line 45

static VALUE oh_obj_for_address(VALUE self, VALUE address)
{
  return FIX2PTR(address);
}

.address_of(obj) ⇒ Object



18
19
20
# File 'lib/objspace_helpers/helpers.rb', line 18

def self.address_of(obj)
  _address_of_obj(obj)
end

.diff(&block) ⇒ Object



22
23
24
25
26
27
# File 'lib/objspace_helpers/helpers.rb', line 22

def self.diff(&block)
  objs_before = dump_all_addresses
  block.call
  objs_after = dump_all_addresses
  objs_after - objs_before - [address_of(objs_after)]
end

.dump_all_addressesObject



2
3
4
# File 'lib/objspace_helpers/helpers.rb', line 2

def self.dump_all_addresses
  _dump_addresses
end

.info_for_address(addresses) ⇒ Object



6
7
8
# File 'lib/objspace_helpers/helpers.rb', line 6

def self.info_for_address(addresses)
  _addresses_to_info(addresses)
end

.info_for_obj(obj) ⇒ Object



10
11
12
# File 'lib/objspace_helpers/helpers.rb', line 10

def self.info_for_obj(obj)
  _addresses_to_info([address_of(obj)]).values.first
end

.obj_for(address) ⇒ Object



14
15
16
# File 'lib/objspace_helpers/helpers.rb', line 14

def self.obj_for(address)
  _obj_for_address(address)
end