Class: Hash

Inherits:
Object show all
Defined in:
lib/stratagem/extensions/hash.rb

Constant Summary collapse

@@listeners =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hash_readsObject (readonly)

Returns the value of attribute hash_reads.



3
4
5
# File 'lib/stratagem/extensions/hash.rb', line 3

def hash_reads
  @hash_reads
end

#hash_writesObject (readonly)

Returns the value of attribute hash_writes.



3
4
5
# File 'lib/stratagem/extensions/hash.rb', line 3

def hash_writes
  @hash_writes
end

Class Method Details

.track_parameter_reads(&block) ⇒ Object



15
16
17
18
19
# File 'lib/stratagem/extensions/hash.rb', line 15

def self.track_parameter_reads(&block)
  @@listeners[block] = []
  yield
  @@listeners.delete(block)
end

Instance Method Details

#[](name) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/stratagem/extensions/hash.rb', line 7

def [](name)
  if (@auditing)
    @@listeners.values.each {|listener| listener << name }
    (@hash_reads ||= []) << name
  end
  ruby_get name
end

#enable_auditingObject



21
22
23
# File 'lib/stratagem/extensions/hash.rb', line 21

def enable_auditing
  @auditing = true
end

#ruby_getObject



2
# File 'lib/stratagem/extensions/hash.rb', line 2

alias_method :ruby_get, :[]